Boost logo

Boost :

From: nee Spangenberg (dsp_at_[hidden])
Date: 2004-01-22 08:26:16


Joaquín M López Muñoz schrieb:

> Well, I endorse Jonathan approach of deriving from a
> non-attachment class. If I understand it clearly, your
> solution cannot be applied to preexisting STL containers
> (am I right?)
>
> >
> > Other point is that you may too easily convert it to list<...> pointer
> > (and loose associated data in the process)
> > and you may easily delete the list<...> pointer.
> >
>
> I'd say that WindowList IS-A std::list, so passing it to
> a function excepting an std::list<WindowControl *> is
> all right. The inadvertent delete is certainly an issue,
> but no more that in other situations where no IS-A
> relationship is involved:
>
> void foo(SomeClass *x)
> {
> delete x;
> }
>
> foo(new SomeClass()); //ok
>
> SomeClass x;
> foo(x); // ko
>
> IMHO, deletion needs extra considerations apart from
> the issue of non-virtual derivation, so it is not so
> bad to apply derivation here. Main benefit is you
> can use this idiom with preexisting classes.
>
> Joaquín M López Muñoz
> Telefónica, Investigación y Desarrollo

The usually acceptable inheritance-for-reuse (inherit-implementation
or WAS-A) idiom would derive protected or private, so you can't
use the wrong delete (at least for private inheritance), but you have
to publish all necessary base members via in-class using-declaration.

Greetings,

Daniel


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