Declaring Overriding Functions override (Notes)

NOTE My notes on Chapter 3, Item 12 of Effective Modern C++ written by Scott Meyers. Some (or even all) of the text can be similar to what you see in the book, as these are notes: I’ve tried not to be unnecessarily creative with my words. :) Overriding != Overloading Example of virtual function overriding: // Base class class Base { public: virtual void doWork(); // ... }; // Derived class from Base class Derived: public Base { public: // virtual is optional // this will "override" Base::doWork virtual void doWork(); // ... }; // This creates a "Base" class pointer to "Derived" class object std::unique_ptr<Base> upb = std::make_unique<Derived>(); // Derived doWork() function is invoked upb->doWork(); This is how virtual function overriding allows to invoke a “derived class function” from a base class interface. ...

September 25, 2021 · 4 min · Kushashwa Ravi Shrimali