Possible Duplicate:
Why is the C++ STL is so heavily based on templates? (and not on interfaces)
Why doesn’t neither stlnor Qt containers implement interfaces. For example, it colud be Enumerable for vectors and lists.
Like this:
template <typename T>
class Enumerable
{
public:
virtual const T at(int k) = 0;
//....
virtual ~Enumerable() {}
};
template <typename T>
class Vector: public Enumerable<T>
{
public:
virtual const T at(int k);
//....
};
As a result, code that I use, forces me to use concrete types of containers, that are used in it.
What is it that you are trying to achieve that you think you cannot do with the standard containers? The answer to your question is that they don’t need to. Using templates you have all the advantages interfaces would bring at zero run-time cost.