Templates and Inheritance
Hi
Can I define that a Template must be a subclass of an interface class?
I have defined an
interface IComparable that expects to compare two items of type T:
1 2 3 4 5 6
|
template <class T>
class IComparable
{
public:
virtual int CompareTo(const T) = 0;
};
| |
I want to apply it to a function template:
1 2 3
|
template <class T>
bool search_array( IComparable<T> &items[], IComparable<T> &item )
{}
| |
Does this look correct?
Thanks
Jeff in Seattle
That looks fine to me...did you get any errors?
Looks okay to me. Did you mean to make the parameter a reference here?
virtual int CompareTo(const T&) = 0;
Topic archived. No new replies allowed.