Synopsis: | Never redefine an inherited non-virtual method |
Language: | C++ |
Severity Level: | 2 |
Category: | Object Oriented Programming |
Description: |
In the following code a non-virtual method is redefined, which is not allowed. class Base { public: // Methods void Foo(); }; class Derived : public Base { public: // Methods void Foo(); // Not allowed !!! }; The reasons can be found in "Effective C++" item 37 (see [Meyers]). When an inherited non-virtual method may not be redefined, it may also not be made virtual in the derived class, as in: class Base { public: // Methods void Foo(); }; class Derived : public Base { public: // Methods virtual void Foo(); // Not allowed !!! }; Exception: this rule doesn't hold for classes that have been derived privately from its base class because in such a case no harm can be done. |