Boost logo

Boost :

From: Bronek Kozicki (brok_at_[hidden])
Date: 2004-01-20 05:24:17


Jonathan Turkanis <technews_at_[hidden]> wrote:
> I'm sorry if you mentioned this possibility and I overlooked it. I

I did not mention this on boost (my fault); but you can find it in
http://groups.google.com/groups?selm=iqcng5nbcgyv%24.2d0tjzuqfftz.dlg%4040tude.net

> think the proper conclusion is the usual one: if you use a
> pointer-to-derived as a pointer-to-base, you can't expect correct
> deletion unless you have a virtual destructor. Do you disagree?

I would use different words, but basicaly this old truth is still valid.
*Under certain circumstances* one may use deleter to provide correct
deletion without polymorphism but still, from OOP point of view, there's
little point using inheritance without polymorhism. On the other hand,
C++ supports more programming paradigms than just OO, thus such deleter
support can be *sometimes* useful. BTW: shared_ptr has the very same
limitation, and AFAIK (limited) use of deleter to provide correct
deletion of non-polymorphic class is not really advertised in its
documentation.

I can see one good use for deleter (providing correct deletion of
non-polymorphic class): when returning pointer to private class derived
from user supplied class, and user is allowed to supply non-polymorphic
class. Example is "universal factory", which simple implementation can
be found at:
http://groups.google.pl/groups?selm=Pine.LNX.4.55.0309040946040.18458@sphinx.mythic-beasts.com
(another, yet not quite finished, implementation of "universal factory"
is here: http://b.kozicki.pl/cpp/T80.cpp - anybody interested in seeing
something similar in boost ?)

Regards

B.


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