Search

32. C++ Function Overriding

C++ Function Overriding

In this article, you will learn about function overriding. Also, you will learn how can assess the overridden function of the base class in C++ programming.
C++ Function overriding
Inheritance allows software developers to derive a new class from the existing class. The derived class inherits features of the base class (existing class).
Suppose, both base class and derived class have a member function with same name and arguments (number and type of arguments).
If you create an object of the derived class and call the member function which exists in both classes (base and derived), the member function of the derived class is invoked and the function of the base class is ignored.
This feature in C++ is known as function overriding.
How function overriding works in C++?


How to access the overridden function in the base class from the derived class?

To access the overridden function of the base class from the derived class, scope resolution operator :: is used. For example,

If you want to access getData() function of the base class, you can use the following statement in the derived class.
Base::getData();
Access the overriden function in the base class in C++