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);
}
The big problem here is that this
is not a Date
but a Date*
. Is there a way to refer to this Date
without a pointer or using this
along with other Date
?
Aucun commentaire:
Enregistrer un commentaire