chpicker
Programmer
- Apr 10, 2001
- 1,316
I created a simple class that contains 3 numeric values, and I want to overload the == operator so I can compare 2 instances of the class. The function will simply test all 3 numeric values and return true only if all 3 are identical. The problem is that the compiler only allows me to pass ONE argument to operator==, so how can I figure out what to compare it to? Here's my code:
When I compile, I get "error C2804: binary 'operator ==' has too many parameters". If I remove the second parameter, it compiles...but what can I put into the function body to actually do the comparison? What do I compare "Loc a" to?
Code:
class Loc
{
public:
int x,y,z;
bool operator==(Loc,Loc);
};
bool Loc::operator==(Loc a,Loc b)
{
if((a.x==b.x) && (a.y==b.y) && (a.z==b.z))
return true;
else
return false;
}