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,cfrom 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 compareDatewith bothTriadandDate- 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 inheritDatefromTriadfor some reason, adding three more fields ... - Harry