Suppose I wanted to overload the "==" operator for a derived class, do I need to rewrite the overload in the derived class header file or is there a way to implement the operator overload in the .cpp file without having to add anything in the header file? And if so, how would the implementation of the derived operator look like in the .cpp?
What my header looks like:
class A
{
public:
A();
~A();
virtual bool operator==(const A &ref) = 0;
protected:
int year;
string note;
}
class B:A
{
public:
B();
~B();
bool operator==(const B &ref); //is this needed or not?
private:
int month, day;
}
If you want to override a virtual function in a child-class, then you need to declare the function override in the child class.
So yes, the declaration is needed.
Think about it this way: The class declaration could be used in many places and many source files, how else would the compiler know that the function has been overridden?