[C++-sig] How to deep-copy and delete a mixed python/C++ object from C++
Paul F. Kunz
Paul_Kunz at slac.stanford.edu
Fri Mar 31 19:57:15 CEST 2006
>>>>> On Fri, 31 Mar 2006 10:48:01 +0200, "Achim H." <achim-bpl at mol-net.com> said:
> Hi, I have a base class in C++ (MyClass), a wrapper class for
> boost::python (Wrapper) and a class derived from that in Python
> (MyPythonClass) that implements a pure virtual function of
> MyClass. So far so good.
> However, when I copy an object of Wrapper in C++, the new instance
> still points to the old python object and calls to the virtual
> function implemented in python will access the old data. I had hoped
> that the wrapper<MyClass> base class would copy the python object
> and everything would work.
> Furthermore, I want to be able to delete the object (in C++) through
> the pointer to its base class (it is stored in a
> std::vector<MyClass*>, together with MyClass objects completely
> implemented in C++). If I do now, the Python object stays around,
> still holds a pointer to a now dead object and at some point tries
> to kill it with not-so-nice consequences.
> How can I achieve both correct copying and deletion semantics ?
I'm not sure about deletion, but here is how I do the copying (with
a lot of help from Dave Abrahams)...
http://www.slac.stanford.edu/grp/ek/hippodraw/lib/FunctionWrap_8cxx-source.html#l00179
More information about the Cplusplus-sig
mailing list