class Triad { private: int a, b, c; public: virtual bool operator == (const Triad &tf)noexcept { return ((a == tf.a) && (b == tf.b) && (c == tf.c)); } }; class Date : public Triad { private: int day; int month; int year; public: bool operator == (const Date &dt)noexcept override ^^^^^^^ { return ((day == dt.day) && (month == dt.month) && (year == dt.year)); } };
|
a
,b
,c
from the base class, and not create new fields. Thenoperator==
will not need to be overridden. - HolyBlackCat pmTriad
, then this is a completely different comparison than withDate
. You can compareDate
with bothTriad
andDate
- but in different ways. Just enter the name inDate
-using Triad::operator==;
, well, I would make these operators constant. Well, and about inheritance - this is why you inheritDate
fromTriad
for some reason, adding three more fields ... - Harry