Lists Home |
Date Index |
- From: Steve Harris <email@example.com>
- To: firstname.lastname@example.org
- Date: 03 Feb 2000 08:27:58 -0800
Stefan Haustein <email@example.com> writes:
> BTW, a similar problem exists in C++:
> consider class A, class B extends A
> you cannot assign an instance of B to an A variable because it may
> consume more memory and thus not fit...
If B extends A, then A was probably not designed to accept assignment
from the then-unknown type B. You can slice B to cram it into A, but
of course you shouldn't. I'm not sure of any scenario where you would
want to assign a concrete B to a concrete A.
> So you need explicit pointers to make really use of inheritance.
Or references. It's only a matter of writing the proper function signatures.
> But with pointers, you cannot really use the STL (no wonder if you
> read what the STL author thinks of OOP). So you also need some
> wrapper classes....
We use the Standard C++ containers with pointers all the time. You can
take a container of A*'s, put your A*'s and B*'s (and any other types
derived from A) into it, and call polymorphic methods on the elements
using the std::mem_fun* functors.
Stepanov is not out to block active use of OOP; he's just saying that
he doesn't find it to be the panacea most claim it is . There was a
long and healthy discussion about this on comp.lang.c++.moderated in
November 1999 .
Steven E. Harris
Primus Knowledge Solutions, Inc.