class Base
{
public:
Base(){Foo();}
~Base(){Foo();}
virtual void Foo(){std::cout<<"base";}
};
class Derived: public Base
{
public:
Derived(){Foo();}
~Derived(){Foo();}
void Foo(){std::cout<<"derived";}
};
{
Derived d;
}
Any idea why this code prints “base” and “received”?
I understand that the advice is not to put virtual function calls inside a constructor or descriptor, I just want to know why the code above will have a behavior. Thanks
source
share