[C++-sig] Re: Boost: virtual inheritance

David Abrahams dave at boost-consulting.com
Sat Sep 6 10:35:21 CEST 2003


Jacek Generowicz <jacek.generowicz at cern.ch> writes:

> Here's the distillation of some classes we are trying to wrap with
> Boost.Python, and the way we are trying to do the wrapping.
>
> ===========================================================
> #include <string>
>
> struct Item {
>   std::string name();
> };
>
> std::string Item::name() {
>   return std::string("hello");
> }
>
>
> class Class : virtual public Item {
>   int foo();
> };
>
> int Class::foo() {
>   return 42;
> }
>
>
> #include <boost/python.hpp>
> using namespace boost::python;
>
> BOOST_PYTHON_MODULE( btry ) {
>
>   class_<Item>("Item", no_init);
>     
>   class_<Class, bases<Item> >("Class")   //, no_init)
>     .def("name", &Class::name);
> ===========================================================
>
>
> It looks as if the virtual inheritance of Item is what is causing the
> trouble. It appears as if the following is the relevant part of the
> compilation error messsage:
>
> /afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/class.hpp:395: pointer
>    to member conversion via virtual base `Item' of `Class'
>
> Making the inheritance non-virtual makes the distilled example, at
> least, work fine.
>
> Any hints would be warmly appreciated.


The quick workaround is:

  .def("name", object(&Class::name))

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





More information about the Cplusplus-sig mailing list