[C++-sig] Confusion about inheritance with boost.python

Noah Schwartz noah.schwartz1 at gmail.com
Wed Oct 4 18:53:35 CEST 2006


On Tuesday 03 October 2006 11:37, David Abrahams wrote:
> Noah Schwartz <noah.schwartz1 at gmail.com> writes:
> > struct AWrap : A, wrapper<A> {
> > 	int f() {
> > 		return 0;
> > 	}
> > };
> >
> > BOOST_PYTHON_MODULE(libnn)
> > {
> > 	class_<AWrap, boost::noncopyable>("A")
> > 		.def("f", pure_virtual(&A::f))
> > 		;
> > }
>
> This doesn't look right.  If A::f is supposed to be exposed as pure
> virtual, you shouldn't be overriding it in AWrap.
From the documentation I got the impression that if you have some class A with 
a pure virtual function and will have classes inherit from A that will 
implement the virtual function, you need to wrap A so that the polymorphic 
relationship will work correctly.

>
> > However when I load my module in python I get a complaint about the
> > undefined symbol A.
>
> Please post the complete text of the complaint.  In fact, please also
> post a reproducible example containing one C++ file and one Python
> file.
I don't have the exact error message anymore. Basically, it seemed like python 
didn't understand what A was and so couldn't understand AWrap. When I 
specified that AWrap had no init and so could not be created, the undefined 
symbol stopped occuring. I think this makes sense.

I think some of my confusion with this simple example stemmed from a more 
general confusion about how to properly expose my classes to Python. I have 
things working correctly now, though.

Thanks,
Noah



More information about the Cplusplus-sig mailing list