[C++-sig] Re: boost.python problem: 'virtual functions and default implementations' tutorial doesn't work

David Abrahams dave at boost-consulting.com
Fri Mar 12 16:38:59 CET 2004

"Colin Irwin" <colin_irwin at hotmail.com> writes:

> I've been able to resolve the error by using the following python module
> definition instead:
> BOOST_PYTHON_MODULE(test_module)
> {
>     class_<Base, BaseWrapper, boost::noncopyable>("Base")
>         .def("function", &Base::function, &BaseWrapper::default_function)
>     ;
> }
> Now this noncopyable is not mentioned in the tutorial file and indeed, I
> don't think it does exactly what I want in this case.  By this I mean it
> prevents copying any of the derived objects in Python doesn't it?

No, it simply tells Boost.Python not to try create a by-value
converter from C++ Base objects to Python, such as would be used to
wrap a C++ function returing a Base object by value.

> Where have I gone wrong?  The tutorial file doesn't seem to work as
> expected.  

Then the tutorial is broken and needs to be fixed.

> My fix doesn't do what I want it do (I think this is right, if
> I've inadvertently prevented copying).  How should I structure my module
> definition/code?

As suggested by Pierre, the additional constructor in BaseWrapper
should work:

     BaseWrapper( PyObject* self_, const Base& copy);

Dave Abrahams
Boost Consulting

More information about the Cplusplus-sig mailing list