[C++-sig] Re: Getting Python Object for C++ object

David Abrahams dave at boost-consulting.com
Thu Aug 14 15:44:10 CEST 2003

"Peter Dimov" <pdimov at mmltd.net> writes:

> David Abrahams wrote:
>>>> Yes, but it won't make the shared_from_this() call succeed unless
>>>> you've assigned that shared_ptr into a->_internal_weak_this.
>>>> [Peter, I notice that enable_shared_from_this.hpp is mentioned in
>>>> the docs and enable_shared_from_this<> is mentioned in the
>>>> sp_techniques doc, but there's no mention of this crucial fact]
>>> Which crucial fact?
>> Sorry.  I mean that a derived class needs to initialize the
>> _internal_weak_this in order to get shared_from_this() to work.
>> Unless I've missed some other crucial fact, of course ;->
> No, the derived class doesn't need to do anything. There is no
> _internal_weak_this in the interface. 

Are we loooking at the same file?  It's a public data member, and
AFAICT there's nothing to initialize it, so that responsibility must
lie with derived classes (or the general public, of course).  Aha!
shared_ptr itself takes care of that when you assign to it.  Thanks
for explaining that.  Using template friends and a private data member
on compilers which support it would've helped clarify that (or
regular docs for enable_shared_from_this, of course)!

> AFAICS the poster's problem is that, as you pointed out,
> python::object(self.get()) creates a new object, not that I know
> anything about (Boost.)Python, of course.

Good guess, then ;-)

Dave Abrahams
Boost Consulting

More information about the Cplusplus-sig mailing list