[C++-sig] Shared_ptr created by python wrapper doesn't know about the python reference?

Peter Dimov pdimov at gmail.com
Fri May 13 15:08:00 CEST 2005

Thomas Schipolowski wrote:


> Please advise me on how to handle this situation correctly. It should
> work the same no matter whether objects are created from python or
> c++.
> Regards,
> Thomas.
> The test code (sorry, its rather long):


> class Slave {
> public:
>    Slave(pMaster m): master(m) {

I'm not sure that I understand what Boost.Python is doing when it sees your 
code, but you may want to try to inherit from enable_shared_from_this<> in 
your Master class and change the Slave constructor to:

    explicit Slave( Master const * pm ): master( pm->shared_from_this() )

More information about the Cplusplus-sig mailing list