[LC++]Generic programming vs OO inheritance
Kai Vehmanen
kai.vehmanen at wakkanet.fi
Tue Aug 21 00:35:09 UTC 2001
On Thu, 16 Aug 2001, Mark Phillips wrote:
> You've almost convinced me on this point. Template "typename" (or
> "class") parameters give no information about the type of class which
> may be passed in. This is in contrast to the OO base-class approach
> where the base-class effectively defines the type of class that
> pointers to this base-class are allowed to represent. This is why I
I've always liked Eiffel's template system. Basicly it ties OO and generic
programming closely together. Here's a short code example:
--cut--
class SUM[T -> NUMERIC]
inherit
COMBINE[T]
feature
[class definition]
--cut--
Ie. class SUM has a generic parameter T, which must be derived from the
NUMERIC base class (interface class). SUM[T] then inherits from another
generic class COMBINE[T].
The same thing happens in C++, but in Eiffel the required interface is
explicitly stated. And this is a very nice feature. For instance all
algorithms working on collections can be templatized with T->COLLECTION,
etc...
My biggest grief with gcc C++ templates is the lack of support for export.
As it is now, I have to include the routine implementations from header
files. In a big project, with widely used template classes, this means
that a small change to the implementation of some template class routine
implementation results in recompilation of practically the whole system.
This is extremely inconvenient.
--
http://www.eca.cx
Audio software for Linux!
More information about the tuxCPProgramming
mailing list