I'm overloading both == and != operators and want the latter to refer to the former in order to not repeat any code at all. This is what I have written:
bool Date :: operator == (const Date & other) const {
bool are_equal = Year() == other.Year();
for (int i=0; i<other.NumEvents() && are_equal; i++)
are_equal = this[i] == other[i];
return are_equal;
}
bool Date :: operator != (const Date & other) const {
return !(this == other);
}
Run Code Online (Sandbox Code Playgroud)
The …