MohamedG's Log

TW9oYW1lZCBFbC1HZWlzaA==

C++: Calling a Virtual Function From a Constructor is not Polymorphic

In C++, if you call a virtual function form a constructor, it won’t be polymorphic, meaning that the following code won’t behave as you may have expected: class Foo { public:     Foo() {         whoAmI();     }     virtual void whoAmI() {         cout << “Foo::whoAmI()” << endl;     } }; class Bar : public Foo { public:     Bar() {         whoAmI();     }     virtual void whoAmI() {        … Read more