[C++-sig] Function taking Virtual Base Pointer

David Abrahams dave at boost-consulting.com
Fri Dec 13 00:10:18 CET 2002


Thomas Muldowney <temas at box5.net> writes:

> I'm trying to implement an event listener class from my C++ library so
> that python scripts can override it and get the events delivered to them
> in the script.  After reading the docs it all seemed possible and easy
> to do.  
<snip>


> BOOST_PYTHON_MODULE(testMOD)
> {
>     class_<A, boost::noncopyable,
>     boost::shared_ptr<A_cb> >("A", no_init);
strike no_init here------------------^^^^^^^
You don't really need shared_ptr; but it's OK.

>     def("test_Aptr", test_Aptr);
> }
>
>
> Python test script:
> from testMOD import *
>
> class MyA(A):
>     ## Don't get yelled at because we pass off to the non existant internal
>     ## constructor
>     def __init__(self):
          
You need to call the base class __init__ here to create the C++
instance.  Or you can do it the easy way; just remove the __init__
function here.

>         pass

>     def onCommand(self):
>         print "We got a command"
>
> a = MyA()
> test_Aptr(a)
>
> Output running it:
> $ python test_ptr.py 
> Traceback (most recent call last):
>   File "test_ptr.py", line 12, in ?
>       test_Aptr(a)
> TypeError: bad argument type for built-in operation
>
>
> I really do love everything, this has just been giving me a headache =)

I love everything too!

-- 
                       David Abrahams
   dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution





More information about the Cplusplus-sig mailing list