Provided the following template:
template <class T>
class MyTemplate {
private:
T myData;
public:
MyTemplate(const T &data) : myData(data) {}
bool Contains(const T &);
};
Is there a way to ensure at compile time that the argument T derives from another class?
I want T to derive from my abstract class Comparable, so that it implements CompareTo and I can call that method from Contains (and other methods) instead of using operators (== < >) which T would have to overload.
I provided the simplest example of MyTemplate, which would make more sense if it where, for example, a linked list (so Contains traverses it and calls CompareTo for each element).
Thanks.