Wrapping classes with pure virtual functions

Roman Yakovenko roman.yakovenko at gmail.com
Sun Dec 17 13:45:43 EST 2006


On 14 Dec 2006 13:57:10 -0800, gabriel.becedillas at gmail.com <
gabriel.becedillas at gmail.com> 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/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20061217/3f5a6a21/attachment.html>


More information about the Python-list mailing list