|
-
Functions in derived classes override virtual functions in base classes only if their type is the same .
-
Redefinition of non-virtual functions may also cause confusion,
especially in a mix-in of virtual and non-virtual functions in one interface.
int main()
{
Derived d;
Derived* dp = &d;
Base* bp = &d;
dp->vf(); // expected Derived::vf
dp->f(); // expected Derived::f
bp->vf(); // expected Derived::vf (it's virtual!)
bp->f(); // expected Derived::f (confusing for virtual)
return 0;
}
/*Program output:
Derived::vf
Derived::f
Base::vf
Base::f
*/
|