[C++-sig] Instance ownership transfer in constructor.

Jani Tiainen redetin at gmail.com
Thu Jul 5 12:49:38 CEST 2012


Hi,

I'm new to python.boost library and I'm trying to use it to wrap a third 
party library. Everything else I've managed to get working - thanks to 
excellent library and lot of examples I've found around a net.

Only thing I can't get working properly is instance ownership transfer 
in constructor.

So classes in library are defined like follows:

class Owner {
...
}

class Data {
     Data(Owner *owner); // <-- Here happens ownership transfer.
}


Python code is like follows:

owner = Owner()
data_1 = Data(owner)
data_2 = Data(owner)

So when Python script stops runnning it causes crash due the fact that 
I've data objects are automatically destroyed by Owner-class but Python 
deletes them by using Data-class destructor (which shouldn't happen ever).

-- 
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...



More information about the Cplusplus-sig mailing list