Re: Deriving from std containers (Was: How to use the iterator from base class in a derived class?)
On 2007-10-20 16:58:47 -0400, Tristan Wibberley <maihem-nn1@maihem.org> said:
>
> On Thu, 2007-10-18 at 08:04 +0000, Erik Wikström wrote:
>
>> The general advice is to not inherit from the standard containers,
>> instead create a class that wraps the container.
>
> I'd heard that was because somebody might use a reference to your object
> with type std::vector<...>& and use all the wrong functions.
This doesn't make sense. I thought the whole point of Object-Oriented
Programming is that polymophisms are encouraged as a coding structure.
If a derived class can potentially ``damaged'' the integrity of the
base class, then as the designer of the base class he shouldn't have
allowed his methods be declared virtual (so that the derived class
could not override it). If so, how then can any reference of the base
class be using any wrong methods supplied by the derived class?
>
> Is there any other problem that makes that a bad idea too?
Yea, I like to know too.
--
-kira
|