Boost logo

Boost :

From: Jonathan Wakely (cow_at_[hidden])
Date: 2005-02-25 11:51:37


On Fri, Feb 25, 2005 at 10:19:57AM -0500, christopher diggins wrote:

> When inheriting from an STL container the constructors and local typedefs
> need to be redeclared. For instance the vector contract class at
> http://www.ootl.org/pwc/pwc_vector.hpp.htm .
>
> It seems to me that it would be very useful to have a single macro for each
> of the different STL containers to ease inheritance of them. Does Boost
> already have something like that? If not would anyone else want something
> like this for Boost? Or am I really missing something basic here, and this
> is a bad idea for some obscure C++ reason?

I think it might encourage people to inherit from concrete classes, not
something to be encouraged. For wrappers like PwC or a stdlib debug mode
it might be necessary, but public inheritance for code re-use is a bad
idea, especially from non-polymorphic classes, and this makes it easy.

If you want vector's interface, do you really want *all* of it?
Because if you inherit publicly you get all of the public members
functions, and with your idea you also get all the constructors and
typedefs! If you really want vector's interface why aren't you using
vector?

If you're going to make it easy to inherit from vector, why not make it
easy to do it with private inheritance or composition, so you can reuse
the code without having to use public inheritance ? I think that culd
be valuable, although often you'd want to selectively enable parts of
the interface, so you can use the insert() functions but not erase(),
for example.

jon

-- 
Progress is not made by early risers.
Progress is made by lazy men looking for easier ways to do things.

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