Difference Between Function Overloading and Overriding in C++

C++Server Side ProgrammingProgramming

In this post, we will understand the difference between function overloading and function overriding in C++.

Overloading

  • No keyword is used during overloading.

  • The prototype differs only based on the number or type of parameter.

  • It happens during compile time.

  • Constructors can be overloaded.

  • Destructor can’t be overloaded.

  • It can be used to achieve early binding.

  • The version of function being called is determined by the number or type of parameter being used.

  • The functions would be redefined with the same name, different number or type of parameters.

Overriding

  • The prototype remains same throughout.

  • It occurs at runtime.

  • Virtual functions can’t be overridden.

  • Destructor can be overridden.

  • Overriding is also known as late binding.

  • The function that would be overridden is preceded by the ‘virtual’ keyword in the base class.

  • The address of the class’s object is assigned to the pointer whose function is called by the pointer.

  • When the function is defined, it is preceded by ‘virtual’ keyword in main class.

  • The same function is redefined in derived class using ‘out’ keyword.

raja
Published on 25-Mar-2021 05:31:44
Advertisements