Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Occurs when a derived class provides a specific implementation for a function that is already defined in its base class.
class Parent {
public:
virtual void show() { cout << "Parent"; }
};
class Child : public Parent {
public:
void show() override { cout << "Child"; } // Override
};The base class function MUST be marked virtual to enable overriding.
Using override (C++11) is optional but helps the compiler catch errors.
Inside the overridden function, you can still call the base class version using the scope resolution operator: Parent::show();