Re: Deriving from a STL container
On Oct 30, 8:59 pm, Kai-Uwe Bux <jkherci...@gmx.net> wrote:
BobR wrote:
mosfet wrote in message...
Could someone tell me why it's considered as bad practice to inherit
from STL container ?
They do not have virtual destructors.
That's an orthogonal issue. The template classes
std::iterator<> or std::unary_function<> also do not have
virtual destructors, yet they are clearly provided to be
inherited from.
Yes, but they were designed to be base classes, std::vector
wasn't. In this case, I think the difference is that classes
like std::iterator<> don't have any semantics; you'd never,
never have an std::iterator<>* in your program, much less delete
through it. This is a lot less true for std::vector<>*.
My own feeling is that std::vector<> isn't designed for use as a
base class, and so shouldn't usually be used as a base class.
On the other hand, if the use were local and well controled, I
don't think I'd get up in arms about it. I would object to it
if the derived class were some general and widely used
component, however.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34