Thursday, 3 October 2013

C++ Template Restriction on having a method

C++ Template Restriction on having a method

I want to learn whether there is a way to restrict templates such that
instances have a specific method. For example, think of a generic isLess
function which needs operator< or operator>. Is there a way to control
that?
template <Class T>
bool isLess(T first,T second){ return first < second; }
When we use this with a class not having operator< it will give an error.
How can I deal with it?

No comments:

Post a Comment