call to pure virtual function from base class constructor

There are many articles that explain why you should never call virtual functions in constructor and destructor in C++. Take a look here and here for details what happens behind the scene during such calls.

In short, objects are constructed from the base up to the derived. So when you try to call a virtual function from the base class constructor, overriding from derived classes hasn’t yet happened because the derived constructors haven’t been called yet.

Leave a Comment