I have the following functor and I had included it in my main program
template<class T> struct Comp: public binary_function<T, T, int>
{
int operator()(const T& a, const T& b) const
{
return (a>b) ? 1: (a<b) ? -1 :0;
}
};
It wasn’t giving any error when it was in the .cpp, but now when I moved it to my .h, it gives me the following error:
testclass.h: At global scope:
testclass.h:50:59: error: expected template-name before ‘<’ token
testclass.h:50:59: error: expected ‘{’ before ‘<’ token
testclass.h:50:59: error: expected unqualified-id before ‘<’ token
So, I rewrote it as:
template<class T> T Comp: public binary_function<T, T, int>
{
int operator()(const T& a, const T& b) const
{
return (a>b) ? 1: (a<b) ? -1 :0;
}
};
and now i get the following error:
testclass.h: At global scope:
testclass.h:50:30: error: expected initializer before ‘:’ token
any suggestion on how I can fix it? thanks!
The original error is probably with
binary_function: missing the include or not considering that it is in namespacestd.and