[C++-sig] Re: Containers for derived classes

David Abrahams dave at boost-consulting.com
Fri Aug 8 13:51:19 CEST 2003


Brett, I hate to be so blunt, but unless I'm misunderstanding you,
this explanation is almost completely wrong.

"Brett Calcott" <brett.calcott at paradise.net.nz> writes:

> The problem is that for python object 'identity' the PyObject must survive
> making it from the python interpreter to C++, and back again. 

True.

> In this case it doesn't -- it is deleted when you set it, and a new
> one is constructed when it returns.

False; with all recent CVS versions boost::shared_ptr<T> converted from
python actually manages the containing Python object and will convert
back into the same object when converted to python.

>
> Try this instead:
>
> ...
>     // class_<A, A_ptr>("A", init< int >() )
>     class_<A, boost::noncopyable>("A", init< int >() )
> ...
>
>
> This does work. Why? Because Boost.Python uses shared_ptr<A> *internally* to
> construct this object

??? False.  Where did you get that idea?  shared_ptr<A> is not used
internally unless you ask for it explicitly AFAICT.

> and it does it in a special way so that the PyObject is referenced
> as part of the shared_ptr<A> construct -- so it survives the round
> trip.


-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list