Boost logo

Boost :

From: Larry Evans (jcampbell3_at_[hidden])
Date: 2002-03-22 23:35:03

Larry Evans wrote:

> Peter Dimov wrote:
> > From: "E. Gladyshev" <egladysh_at_[hidden]>


> >--------------------------------
> Another post(msg23390.php), the following:

 ^^^^^^^^^^^^^ should be "In another post"...

> <--------------------------------
> shared_ptr<Base> createObject(std::string classId);
> >--------------------------------
> was suggested by Peter as an example of when the shared_ptr
> CTOR call, does NOT know the most derived class of the pointer.

  ^^^^^^^^^^^^ should be "CTOR call does NOT know" ...

> Now if createObject actually creates a subclass of Base, then
> the wrong delete may be called. I assume Peter meant that
> createObject(...) returns a Base* and the shared_ptr<Base>
> ::shared_ptr(Base*) CTOR is called. On the other hand, if
> Peter meant that createObject actually returns a shared_ptr<T> where
> T is the most derived class, then there's no problem. I see no
> what that the current shared_ptr can avoid problems if Peter meant

 ^^^^^^^^^^^^^^^^^^^^^ should be "way that the current"

> that createObject returns a Base* and the delete_able_ptr proposal
> won't help either.
> In summary, what I'm proposing is using delete_able_ptr as an arg
> to shared_ptr CTOR to avoid the current problem as well as the

It actually would avoid the problem by preventing it from occurring.
It's somewhat like Robert's suggestion in msg27298.php, except that
auto_ptr<T>::auto_ptr(T*) is allowed, which simply moves the problem
from share_ptr CTOR to auto_ptr CTOR. The delete_able_ptr CTOR won't
allow anything but a delete-able pointer to be returned from release.

> problem with multiple inheritance and the problem raised by
> Tom Becker (msg23135.php). I see no way of getting createObject
> code above to work correctly. I think another version, maybe name
> createSharedObject which creates a shared_ptr<T> but returns a
> shared_ptr<Base>, where T is subclass of Base.

The last sentence should be "I think another version, maybe named
createdSharedObject, would create a shared_ptr<T> but return a
shared_ptr<Base>, where T is a subclass of Base."

Sorry for the bad grammar.

Boost list run by bdawes at, gregod at, cpdaniel at, john at