In C++, is a function automatically virtual if it overrides a virtual function?
I would expect that if foo is declared in class D , but not marked virtual, then the following code would call the implementation of foo in D (regardless of the dynamic type of d ). D& d = ...; d.foo(); However, in the following program, that is not the case. Can anyone explain this? Is a method automatically virtual if it overrides a virtual function? #include <iostream> using namespace std; class C { public: virtual void foo() { cout << "C" << endl; } }; class D : public C { public: void foo() { cout << "D" << endl; } }; class E : public D { public: void foo() { cout << "E" << endl; } }; int