The reason why I ask is because I am unfamiliar with the idea of
templates. It seems like it would be easier if all classes that
needed something like
template<class T> class Stack { ... }
could be done with just some generic superclass, instead of using a
template.
If this is not the case, does the reason have something to do with
performance, or is it just an alternative that was not thought of?
This was thought of and, in fact, implemented in most early class
libraries, such as the MFC, OWL, one from the NIH, etc. Performance,
while reduced somewhat, is the least of its problems.
Class libraries ultimately reflect the organization that produce them.
A single hierarchy with a single root is almost always the product of
a single organization that the rest of the world receives as more or
less a fait accompl (e.g. Xerox PARC/Smalltalk, Sun/Java, OWL/Borland,
MFC and .NET/Microsoft, the NIH class library, etc. ad naseum).
If you have a large number of more or less independent contributors,
that model becomes almost impossible to manage -- different people and
different purposes lead to different requirements on the base class.
In many cases, these requirements are mutually contradictory. Even
when they are not mutually contradictory, a single hierarchy almost by
definition increases coupling between all the classes involved, even
those that have little or no other reason to be related at all.
The result is that development of a single hierarchy requires a
relatively high degree of cooperation and coordination between all
parties doing any significant development related to it. If the
situation remains one of a single developer with others having far
smaller roles, this can be reasonable. When/if you have a large number
of contributors and (particularly) when the contributors start to
contribute more equally, this model becomes less manageable. When (as
in the case of C++ in general) you start out with a huge number of
people with conflicting ideas of what needs to be accomplished (to the
extent that even the language proper has become somewhat fragmented,
such as Embedded C++) there is essentially no possibility of producing
a single hierarchy that would be of any real use to anyone.