Boost logo

Boost Users :

From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2005-04-28 08:13:08


David Gruener wrote:
> Russell Hind wrote:
>> Only if you pass it to another object. It it is a private shared_ptr
>> then it gets automatically deleted, but won't get shared around.
>
> What i mean is, that if a class is implemented with a pimpl
> structure using boost::shared_ptr this
>
> A a;
> A b(a);
>
> would result in that changing private members of a changes
> private members of b, which one doesn't want
> in the default cases of pimpl.

and if you define:

class A
{
    class Impl;

    typedef boost::shared_ptr<Impl> tPimpl;

    tPimpl mPimpl;

    ...
};

A::A( const A::A& a ):mPimpl( new Impl( *a.mPimpl ) ){}

and don't forget operator=;

You get the deep copy semantics that your looking for don't you?

>> But what about scoped_ptr?
>
> No, scoped_ptr is noncopyable. Whats needed is a
> template with deepcopying the parameter struct (or cloning)
> and no need of an complete type at the point of the declaration
> of the pimpl.

I'd think scoped_ptr works above as well.

Jeff Flinn


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net