Generally, like this:
struct X
{
int a;
double b;
std::string c;
};
bool operator==(const X & lhs, const X & rhs)
{
if(lhs.a != rhs.a) return false;
if(lhs.b != rhs.b) return false;
if(lhs.c != rhs.c) return false;
return true;
}
You can also overload it as a member function if you want:
struct X
{
int a;
double b;
std::string c;
bool operator==(const X & rhs) const
{
if(a != rhs.a) return false;
if(b != rhs.b) return false;
if(c != rhs.c) return false;
return true;
}
};
Notes:
It doesn't have to return a bool. It can return anything or even nothing(void). But I wouldn't recommend returning anything other than bool, because it gives your class a sensible interface that matches the usage of operator== in built-in types.
The two parameters don't have to be the same type. For example, you might write a string class, and you might write an overload of op== that accepts one of your strings as the first parameter, and a 'const char *` as the second parameter, that way you can do things like this:
MyStringClass str;
if(str == "hello") blah();
However, this is unnecessary if your class has a conversion constructor from that other type. That's exactly how the standard library string class does it.