> shared_ptr has no ownership, it keeps the pointer, copies the pointer on
> assignment and the first shared_ptr to die, kills the pointer it keeps
> with it. Ofcourse if you know where the pointer should not die, you can
> use .reset(0) to say so.

Uhuh... I knew I did something wrong... This will hit me when I will try
not to leak memory anymore...
 
> smart_ptr has shared ownership by using reference count, that is, for
> each copy of the shared_ptr the count is increased, when a copy dies,
> the count is decreased, when the count goes to zero, the pointer dies.
> Note that you if you got the pointer out of the smart_ptr, it will be
> dead too, since the smart_ptr isn't smart enough to know about this.

But I could surely access the pointer somehow without destroying it, can't
I?

> auto_ptr has ownership, when you create it, it has ownership over the
> pointer, ownership means that when the owner dies the pointer dies, if a
> non-owner dies, the pointer doesn't die. When you copy the auto_ptr,
> ownership is transferred to the new copy, the old copy loses his
> ownership. A case to be worry of is calling a function passing auto_ptr,
> you may lose the ownership of the auto_ptr and lose the pointer due to
> that. You should also note if the function insides copies the auto_ptr.
> 
> Anyhow, without reference count or the auto_ptr ownership method it is 
> hard to decide when to delete the pointer, and so it is hard to have a
> smart_ptr without one of these two mechanisms.

Well, reference counting might not be bad after all.

I need something that wraps an T* in such a way that I could include this
wrapper in a class (in the sense of containment) and the automatic copy
constructor, assignment operator and desctuctor should work as expected.

I do not need to pass such things to functions a copy.

So what would I use?

Andre'

-- 
André Pönitz ............................................. [EMAIL PROTECTED]

Reply via email to