Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2003-12-11 07:00:44

AlisdairM wrote:
> The shared_ptr library is far more flexible than I realised. I've
> been discovering new tricks all week and thought I would share the
> latest.
> Conventional wisdom says a base class should either have a public
> virtual destructor, if intended for use polymorphically, or a
> protected non- virtual destructor if derivation is purely to inherit the
> implementation.
> With shared_ptr, we can use this second type of class polymorphically
> as well!
> [see example below]
> Not sure this is actually useful though, as I'm sure the shared_ptr
> overhead is more than the cost of adding a virtual destructor ;¬ )

It is not the virtual destructor overhead that is important, it is the
protected access. It means that the user can't delete a pointer to the base

Have you read


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