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?
As far as I know, from reading Stroustrup's books, he did not like the
concept of a single hierarchy with a single root class 'Object'. A
consequence of this design is that you can only inherit from one
class. However, you can still implement many interfaces. His
reasoning was that some classes will have a brittle relationship in
the hierarchy.
Having a generic super class can lead to trouble. First, as others
have already mentioned, you lose type safety. Although, I personally
have not found that to be a problem when I use Java or Delphi.
Second, and more importantly, someone may attempt to derive a
container class from the super container class. The Liskov
Substitution Principle will be violated.
Nicholas