oop - virtual operator overloading c++ -
suppose wanted overload "==" operator derived class, need rewrite overload in derived class header file or there way implement operator overload in .cpp file without having add in header file? , if so, how implementation of derived operator in .cpp?
what header looks like:
class { public: a(); ~a(); virtual bool operator==(const &ref) = 0; protected: int year; string note; } class b:a { public: b(); ~b(); bool operator==(const b &ref); //is needed or not? private: int month, day; }
if want override virtual function in child-class, need declare function override in child class.
so yes, declaration needed.
think way: class declaration used in many places , many source files, how else compiler know function has been overridden?
Comments
Post a Comment