I am trying to overload the ‘>’ operator taking a pointer in parameter, however I get an error saying “operator > must have at least one parameter of type class”. I do not get that error if I do not use pointer.
Note: S1 is a typedef’d structure, as well as elem.
bool operator>(S1 const *V1, S1 const *V2){
if (V1->elem->code > V2->elem->code)
return true;
return false;
}
I use the operator in a case like this, for example :
S1 * funct(S1 *var1, S1 *var2){
if (var1 > var2)
return var1;
return var2;
}
The compiler will want to turn your example into comparing the two pointer values. Having one parameter as a class type will tell it what it needs to know to resolve the overload.
Also, and I’m a bit rusty on this, but I think you have to declare the operator as a friend of S1, or make it a memeber.