[C++-sig] Boost: virtual inheritance

Jacek Generowicz jacek.generowicz at cern.ch
Fri Sep 5 17:25:20 CEST 2003


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.




For completeness (and your enjoyment), we include the full error message ...


gcc -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -I/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/ -I../../../../Dictionary/Reflection -I/afs/cern.ch/sw/lcg/external/Python/2.2.2/rh73_gcc32/include/python2.2 -c boosttry.cpp -o build/temp.linux-i686-2.2/boosttry.o -g
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/class.hpp: In 
   member function `void boost::python::class_<T, X1, X2, X3>::def_impl(const 
   char*, Fn, const Helper&, ...) [with Fn = std::string (Item::*)(), Helper = 
   boost::python::detail::def_helper<const char*, 
   boost::python::detail::not_specified, boost::python::detail::not_specified, 
   boost::python::detail::not_specified>, T = Class, X1 = 
   boost::python::bases<Item, boost::mpl::void_, boost::mpl::void_, 
   boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, 
   boost::mpl::void_, boost::mpl::void_, boost::mpl::void_>, X2 = 
   boost::python::detail::not_specified, X3 = 
   boost::python::detail::not_specified]':
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/class.hpp:246:   instantiated from `boost::python::class_<T, X1, X2, X3>& boost::python::class_<T, X1, X2, X3>::def(const char*, F) [with F = std::string (Item::*)(), T = Class, X1 = boost::python::bases<Item, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_>, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]'
boosttry.cpp:33:   instantiated from here
/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'
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/object/inheritance.hpp: In
   static member function `static boost::python::objects::dynamic_id_t 
   boost::python::objects::polymorphic_id_generator<T>::execute(void*) [with T 
   = Class]':
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/object/inheritance.hpp:78:   instantiated from `void boost::python::objects::register_dynamic_id(T*) [with T = Class]'
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/object/class_converters.hpp:77:   instantiated from `void boost::python::objects::register_class_from_python(Derived*, Bases*) [with Derived = Class, Bases = boost::python::bases<Item, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_>]'
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/class.hpp:476:   instantiated from `void boost::python::class_<T, X1, X2, X3>::register_() const [with T = Class, X1 = boost::python::bases<Item, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_>, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]'
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/class.hpp:494:   instantiated from `boost::python::class_<T, X1, X2, X3>::class_(const char*, const char*) [with T = Class, X1 = boost::python::bases<Item, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_>, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]'
boosttry.cpp:29:   instantiated from here
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/object/inheritance.hpp:48: cannot
   dynamic_cast `p' (of type `class Class*') to type `void*' (source type is 
   not polymorphic)
error: command 'gcc' failed with exit status 1





More information about the Cplusplus-sig mailing list