
Hi John, Usually the best place for Boost.Python questions is: http://www.python.org/sigs/c++-sig/ John Hunter <jdhunter@ace.bsd.uchicago.edu> writes:
I am trying to get raw pointers and abstract base classes working properly with boost::python v2. I am working on an example inspired by the tutorial http://www.boost.org/libs/python/doc/tutorial/doc/inheritance.html.
BTW, more up-to-date docs are here: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/boost/boost/libs/p...
In my case, the base class has a pure virtual function, but I don't need to override it in python and call it from c++, so I don't think I need to do a BaseWrap.
The problem is that if I try and expose Base to python, I get the compiler (gcc 3.2) error:
g++ -isystem/usr/local/include -I/usr/local/include/python2.2 -fPIC -ftemplate-depth-100 -c rawpointer.cpp /usr/local/include/boost/python/object/value_holder.hpp: In instantiation of `boost::python::objects::value_holder<Base>': /usr/local/include/boost/type_traits/alignment_of.hpp:52: instantiated from `boost::detail::alignment_of_impl<boost::python::objects::value_holder<Base> >' /usr/local/include/boost/python/object/instance.hpp:29: instantiated from `boost::alignment_of<boost::python::objects::value_holder<Base> >' ...snip... rawpointer.cpp:47: instantiated from here /usr/local/include/boost/python/object/value_holder.hpp:36: cannot declare field `boost::python::objects::value_holder<Base>::m_held' to be of type ` Base' /usr/local/include/boost/python/object/value_holder.hpp:36: because the following virtual functions are abstract: rawpointer.cpp:15: virtual const std::string& Base::get_name() rawpointer.cpp:14: virtual void Base::sayit() const make: *** [rawpointer.o] Error 1
Yeah, it's trying to instantiate the copy constructor for your base type.
BOOST_PYTHON_MODULE_INIT(rawpointer) { class_<Base>("Base", no_init) .def("sayit", &Base::sayit);
Try class_<Base, noncopyable>("Base", no_init) .def("sayit", &Base::sayit); instead.
class_<Foo, bases<Base> >("Foo") .def("sayit", &Foo::sayit); class_<Bar, bases<Base> >("Bar") .def("sayit", &Bar::sayit);
def("foofactory", foofactory, return_value_policy<manage_new_object>()); def("barfactory", barfactory, return_value_policy<manage_new_object>());
def("simonsays", simonsays); }
-- David Abrahams dave@boost-consulting.com * http://www.boost-consulting.com Boost support, enhancements, training, and commercial distribution