Reputation: 355
I know the title's statement is true.
What about a regular function?
For example
class Father {
virtual void foo() {...;}
}
class Son : public Father {
void foo() {...;}
}
class GrandSon : public Son {
void foo() {...;}
}
Can GrandSon override Son's foo? In general, if your base class has a virtual function, the derived class's corresponding function is automatically virtual? Is this true?
Upvotes: 3
Views: 294
Reputation: 68598
2: If a virtual member function vf is declared in a class Base and in a class Derived, derived directly or indirectly from Base, a member function vf with the same name, parameter-type-list, cv-qualification, and ref-qualifier (or absence of same) as Base::vf is declared, then Derived::vf is also virtual (whether or not it is so declared) ...
Upvotes: 4
Reputation: 249123
Yes, in C++ a derived class "inherits" the virtual aspect of all methods--not just destructors.
Upvotes: 4