Difference Between Function Overloading And Function Overriding In C++

Function Overloading

When we have multiple functions with the same name but different parameters, then they are said to be overloaded. This technique is used to enhance the readability of the program. There are two ways to overload a function, they are:

  • Having different number of arguments
  • Having different argument types.

Function overloading is normally done when we have to perform one single operation with different number or types of arguments.

Properties Of Function Overloading

  • Function overloading is a feature that allows us to have same function more than once in a program. Overloaded functions have same name but their signature must be different.
  • Overloading can be done with or without classes.
  • The prototyping of overloading is totally dependent on the number of parameters or the same parameter with different datatype.
  • Overloading is accomplished at compile time.
  • Function overloading takes place without any inheritance.
  • Overloading is used to have the same name of the functions which behave differently depending upon parameters passed to them.
  • In function overloading, function signature should be different for all the overloaded functions.
  • The overloaded functions are always in the scope.
  • Overloading yields appropriate results, almost every time depending on the skill of programmer and the real-time application.
  • Overloading is used to achieve compile time polymorphism.

What Is Function Overriding?

If both the parent and child class have a member function with the same name and same number of arguments, then we have to create an object of the child class, and we call the member function present in both the child and parent class with the very same name and an equal number of arguments. Then, the member function of the child class is called, and the member function of the base class is ignored. This concept is what is referred to as Function Overriding.

Properties Of Function Overriding

  • Function overriding is a feature that allows us to have a same function in child class which is already present in the parent class.
  • Overriding can only be done in classes.
  • In overriding, all the prototyping aspects are constant.
  • Overriding is accomplished at runtime.
  • Function overriding take place when one class is inherited by the other class. It can’t be done without inheritance.
  • Overriding is required when the derived class adds information to the same member function of the base class.
  • Overridden functions must have the very same name and the same number of arguments. In other words, function signatures must be the same.
  • Overridden functions have a different scope concerning the object of the class.
  • Overriding if not practiced carefully can produce unwanted results because of different early binding and late binding techniques.
  • Overriding is used to achieve runtime polymorphism.

Also Read: Difference Between Compile Time And Runtime Polymorphism

Difference Between Function Overloading And Function Overriding In Tabular Form

BASIS OF COMPARISON   FUNCTION OVERLOADING FUNCTION OVERRIDING
Description Function overloading is a feature that allows us to have same function more than once in a program. Overloaded functions have same name but their signature must be different.   Function overriding is a feature that allows us to have a same function in child class which is already present in the parent class.  
Implementation It can be done with or without classes.   It can only be done in classes.  
Prototyping Aspects The prototyping of overloading is totally dependent on the number of parameters or the same parameter with different datatype.   All the prototyping aspects are constant.  
Accomplishment It is accomplished at compile time.   It is accomplished at runtime.  
Inheritance Function overloading takes place without any inheritance.   Function overriding take place when one class is inherited by the other class. It can’t be done without inheritance.  
Use It is used to have the same name of the functions which behave differently depending upon parameters passed to them.   It is required when the derived class adds information to the same member function of the base class.  
Function Signature In function overloading, function signature should be different for all the overloaded functions.   Overridden functions must have the very same name and the same number of arguments. In other words, function signatures must be the same.  
Scope The overloaded functions are always in the scope.   Overridden functions have a different scope concerning the object of the class.  
Advantage/Disadvantage Overloading yields appropriate results, almost every time depending on the skill of programmer and the real-time application.   Overriding if not practiced carefully can produce unwanted results because of different early binding and late binding techniques.  
Goal It is used to achieve compile time polymorphism.   It is used to achieve runtime polymorphism.