Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-01-18 16:19:49


----- Original Message -----
From: "Peter Dimov" <pdimov_at_[hidden]>
class hierarchy without a virtual base class destructor?
>
> Good question.
>
> Is there a realistic use case where the Derived* -> Base* implicit
> conversion is useful when Base is not polymorphic? ;-)

Absolutely. You can use inheritance for implementation sharing, to reduce
coupling, etc. Maybe the objects aren't even intended to be dynamically
allocated, but linked into a chain on the stack or in global space, for some
reason. The this pointer itself is implicitly converted when calling a base
class function. There are lots of useful designs where non-polymorphic
inheritance can be employed.

The key difference with a non-polymorphic implicit upcast is that pointers
don't, by themselves, manage the lifetimes of their referents. So, there's
no problem with the implicit conversion until you add some meaning to it,
like ownership.

-Dave


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