On 14 Dec 2006 13:57:10 -0800, [EMAIL PROTECTED] <
[EMAIL PROTECTED]> wrote:
Hi,
I'm having problems wrapping a hierarchy of classes, actually having
problems wrapping the base class. I don't need to use the WrapClass
mechanism since I don't want to override classes in Python. My code
boils down to:

class Base
{
public:
        virtual ~Base()
        {}

        virtual void f() = 0;
};

class Derived :
        public Base
{
public:
        virtual void f()
        {}

        void g()
        {}
};

int main()
{
        boost::python::class_<Base> class_base("Base");
        boost::python::class_<Derived> class_derived("Derived");
        return 0;
}


namespace bpl = boost::python;
bpl::class_<Base, boost::noncopyable>("Base", bpl::no_init )
   .def( "f", bpl::pure_virtual( &Base::f ) );

bpl::class_< Derived, bpl::bases< Base > >( "Derived" )
   .def( "f", &Derived::f )
   .def( "g", &Derived::g );

Few comments:
1. It is better to ask Boost.Python related questions on its mailing list:
   http://mail.python.org/mailman/listinfo/c++-sig/
2. If you just start with Boost.Python, try Py++
  ( http://language-binding.net/pyplusplus/pyplusplus.html )
Boost.Pythoncode generator
  It has nice GUI ( no need to learn any API ):

http://language-binding.net/pyplusplus/documentation/tutorials/pyplusplus_gui.html


--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to