I have a question about calling operators of a base class from a derived class. Here's some sample code:The bold part is the part I'm wondering about. I know I can do it that way and it seems to work, but is there a prettier way to do it? I realize that I could have m_a be protected instead of private and then test, but m_a needs to be private. I was hoping for some sort of syntax that didn't have operator== explicitly stated and that looked more like a normal == test.Code:#include <iostream> using std::cout; using std::endl; class Base { public: Base(int a) : m_a(a) {} bool operator==(const Base& op1) { return (m_a == op1.m_a); } private: int m_a; }; class Derived : public Base { public: Derived(int a, int b) : Base(a), m_b(b) {} bool operator==(const Derived& op1) { return (((Base*)this)->operator==(op1)) && (m_b == op1.m_b); } private: int m_b; }; int main() { Derived a(10,3), b(10,3); if (a == b) cout << "Equal" << endl; else cout << "Not equal" << endl; return 0; }
Thanks.