Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-01-20 06:30:37

From: "Thomas Maeder" <maeder_at_[hidden]>
> Am 2002.01.18 21:36 schrieb(en) Peter Dimov:
> > Good question.
> >
> > Is there a realistic use case where the Derived* -> Base* implicit
> > conversion is useful when Base is not polymorphic? ;-)
> Not so good question, because the answer is obvious. :-)
> But I'm not sure if the two questions are as connected as they might
> seem to. I use a shared_ptr to express object ownership; and we all
> know that it's rarely wise to express ownership of a Derived object
> through a (shared) pointer to Base if the Base destructor isn't virtual.
> I don't think that my question has been answered yet.

It's not. That's why it's a good question.

Some situations where the T* -> void* conversion can be exploited are where
the pointers are stored as void*, along with a function that casts this
void* back to T*. This is to get rid of the templatization; this is
something like defining functions taking boost::any instead of a function
template taking T. That's what I had in mind.

Other times you have a function that takes shared_ptr<Base> and that Base is
read-only and doesn't have a virtual destructor, but you need to derive from
it (to "fix" it.)

Anyway, there's no has_virtual_destructor<> trait. ;-)

Peter Dimov
Multi Media Ltd.

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