[C++-sig] Inheritance question

Stefan Seefeld seefeld at sympatico.ca
Fri Feb 10 14:32:37 CET 2006


Koen Van Herck wrote:
> Hello,
> 
> I want to expose the following classes in Python:
> 
> class Base
> {
> public:
>     virtual void f() = 0;
> };
> 
> class Derived: public Base
> {
> public:
>     void f() { std::cout << "Derived::f" << std::endl; }
>     void g() { std::cout << "Derived::g" << std::endl; }
> };
> 
> class User
> {
> public:
>     void useBase(Base & b) { b.f(); }
> };
> 
> I've created the following code in my BOOST_PYTHON_MODULE
> 
>     class_<User>("User")
>         .def("useBase", &User::useBase)
>     ;
> 
>     class_<Derived>("Derived")
>         .def("g", &Derived::g)
>     ;

This should be class_<Derived, bases<Base> > ...

Regards,
		Stefan



More information about the Cplusplus-sig mailing list