Define the method once to be virtual in the inheritance hierarchy to make polymorphism to work
问题 Is it sufficient to define the method once to be virtual in the inheritance hierarchy to make polymorphism to work. In the following example Der::f is not defined to be virtual but d2->f(); prints der2 I am using VS IDE (may be it is only there...) class Base { public: virtual void f() { std::cout << "base"; } }; class Der : public Base { public: void f() { std::cout << "der"; } //should be virtual? }; class Der2 : public Der { public: void f() { std::cout << "der2"; } }; int main() { Der* d2