Boost logo

Boost :

From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2007-09-06 08:49:22


Edd Dawson wrote:

> I'm confused. Surely the whole point of shared_ptr is to relieve the programmer
> of the burden of worrying when its still used.

The problem is that with large programs you're not able to tell easily
where it is being used. (also, you may create cycles by oversight, but
that could be fixed eventually)
The fact that it is automatically destructed when not used doesn't not
mean that it can't be still used at wrong places, especially after code
refactoring and modifications.

> And what side effects do you
> speak of?

http://en.wikipedia.org/wiki/Side_effect_%28computer_science%29

> How are programs made more deterministic?

Because ownership is fixed to a scope. You thus perfectly know when the
object will be constructed and destructed.
With shared ownership, ownership is fully dynamic, and thus not determined.

> Actually, if you have the static type at the point of construction, you're set.
> Here's one I just threw together: http://rafb.net/p/bIQgtl24.html

I looked at your code and I am not sure throwing an exception is the
right thing to do if the static and dynamic types aren't the same.

The stuff should "just work".

In your code also you used 'new' directly. It is obvious that people may
want to use their custom allocator.
Plus, if you think about it, a virtual constructor should only be
responsible for constructing, not allocating the memory for the object.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk