[C++-sig] Re: [boost] mirroring class instances between c++ and python
David Abrahams
david.abrahams at rcn.com
Sat Jun 1 22:56:00 CEST 2002
David,
Please post followups to the C++-sig (c++-sig at python.org).
----- Original Message -----
From: "David GD Wilson" <firestar at thenorth.org>
> 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
More information about the Cplusplus-sig
mailing list