C++ Function Overriding


What is function overriding?

  • The function overriding means when the function has the same name, same return type and same parameters.
  • The function overriding also means when the derived class defines the same function as defined in its base class.
  • Through function overriding you can perform runtime polymorphism.
  • The function overriding allows you to have the same function in child class which is already defined in the parent class.
  • The child class inherits the data members and member functions of parent class but if you want to override a function in the child class then you can use function overriding.

Let us have a look at the example:

Difference between Function Overloading and Function Overriding

Function Overloading

Function Overriding

The function overloading can be done without inheritance. The function overriding occurs when once class is inherited from another class.
In function overloading it should have a different signature either in the form of number of arguments or type of arguments. In function overriding the function signature should be same.
The function overloading is done in the same scope. The function overriding is done in different scopes.
The function overloading have same name of functions which behave differently depending upon the parameters passed. The function overriding is required when derived class function has to do some different tasks than the base class function.


Like it? Please Spread the word!