Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-06-01 15:56:00


David,

Please post followups to the C++-sig (c++-sig_at_[hidden]).

----- Original Message -----
From: "David GD Wilson" <firestar_at_[hidden]>

> Hi,
>
> I am hoping someone has managed to get this problem working before and
> can give me some pointers as to how to accomplish the task.
>
> What I am trying to do is have a class in C++ that is mirrored in
> python. This means that each instance of a class that is created will
> have a python class created along with it and that python instance can
> call into the c++ instance and vice versa.

That's the normal case for classes which have overridable virtual functions
as described at http://www.boost.org/libs/python/doc/overriding.html.

Why not just use class_builder<CTest,CTest>?

Every constructor you expose must have a hidden initial PyObject* parameter
not described in the parameters to constructor<...>, so:

struct CTest
{
    CTest(PyObject* self, Arg1 a1, Arg2 a2...)
        : m_self(self)
          ...
    {
        ...
    }

    ...

    PyObject* m_self;
};

class_builder<CTest,CTest> test(module,"PTest");
test.def(constructor<Arg1,Arg2...>())

HTH,
Dave


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk