[C++-sig] Re: Inheritance with B/P

David Abrahams dave at boost-consulting.com
Fri Feb 7 23:40:57 CET 2003


Bruce Lowery <bruce_lowery at yahoo.com> writes:

>> For me it's look like a C++ problem not a Python problem.
>> auto_ptr<Derived> is not inherited from auto_ptr<Base> and/or
>> there is no automatic conversion from former to later.
>> 
>
> You are right.

That's not the problem in the sample you posted.

> Turns out I left out another detail - the method that's being called with the
> derived class instance, is itself wrapped by a function call.  For instance,
>
> class SomeOther { void someFunc( Base* b ); }
>
> void someFunc_wrap( SomeOther& self, auto_ptr<Base> b ) 
> { self.someFunc(b.get()); }
>
> BOOST_PYTHON_MODULE(Foo){ class_<SomeOther>("SomeOther",...)
> .def( "someFunc",someFunc_wrap ); }
>
>
> Previously, I just had '.def("someFunc",&SomeOther::someFunc)'  which works,
> evidently because b/p takes care of the conversion.

You've still left out a lot of detail.  How hard can it be to assemble
a reproducible case based on the code you're posting here?  You might
discover that your problem is elsewhere (if it works), which would
save both of us a lot of wasted effort ;o).  Otherwise, I'd be able to
check it out and tell you where the problem is.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list