Difference between Function Overloading and Function Overriding in C++


FUNCTION OVERLOADING

Function overloading is a component where at least two functions can have a similar name with different arguments and can be considered as an instance of polymorphism.

FUNCTION OVERRIDING

Function overriding is a component that enables us to have an equivalent function in child class which is already defined in the parent class. A child class acquires member variables and member functions of its parent class. When there is a need to override the functionality of the parent’s member function then we use the concept of function overriding. It resembles making another adaptation of an old method, in the child class.

DIFFERENCE BETWEEN FUNCTION OVERLOADING AND FUNCTION OVERRIDING:

  1. The prototyping of overloading is totally dependent on the number of parameters, whereas; in overriding all the prototyping aspects are constant.
  2. In overloading, we do not require any kind of special keyword, whereas; in overriding the function in the base class needs to be preceded with ‘virtual’ keyword in order to be overridden in the child class.
  3. Overriding of functions can be done when one class is inherited by the other class. Overloading can take place without any inheritance.
  4. The overloaded functions must contrast in function signature for example either number of parameters or sort of parameters should be different. In overriding, function signatures must be similar.
  5. The overloaded functions are always in the same scope, whereas; in overriding, the functions are in different scope always.
  6. Overriding is required when a determined class function needs to perform some additional or unexpected job in comparison to the base class function. Overloading is utilized to have the same names of various functions which act distinctively relying on parameters handed over to them.
  7. The overloading is accomplished at compile time, whereas; the overriding is accomplished at runtime.

You would also like


Posted in Articles and tagged , , , , , , .

Leave a Reply

Your email address will not be published. Required fields are marked *