Function Overloading vs. Overriding in C++

The key difference between function overloading and overriding in C++ is that function overloading in C++ is compile-time polymorphism whereas overriding in C++ is a run-time polymorphism.

Advertisement - Continue Reading Below
Function Overloading vs. Overriding in C

Using one name for multiple forms and types is known as polymorphism. Polymorphism is one of the most important concepts in Object oriented programming. There are many ways of implementing polymorphism that function overloading, overriding and virtual function. Function overloading in C++ is compile-time polymorphism whereas overriding in C++ is a run-time polymorphism.

Overloading is compiled time polymorphism. Overloading provides a common interface for multiple methods. Overloading mean code contains same function name while it is redefined. Overloading makes one overloaded function different from other function. There are different parameters of overloading function.

Run-time polymorphism is known as overriding. Overriding is achieved by using a function keyword that is virtual. This keyword is use in base class. When derived class redefine a function, overridden function cannot be changed. Overriding in C++ determines that which version of the function is called.

Contents: Difference between Function Overloading and Overriding in C++

Comparison Chart

BasisOverloadingOverriding
MeaningFunction overloading in C++ is compile-time polymorphism

Function overriding in C++ is a run-time polymorphism.

Advertisement - Continue Reading Below

 

Keyword There is a specific keyword in overloading“Virtual” is a specific keyword in function overriding.
Accomplishment In overloading function, there is compile time accomplishment.In function overriding, there is a run-time accomplishment.
Binding In function overloading, there is early bindingIn function overriding, there is late binding

 Overloading

Overloading is compiled time polymorphism. Overloading provides a common interface for multiple methods. Overloading mean code contains same function name while it is redefined. Overloading makes one overloaded function different from other function. There are different parameters of overloading function.

Overriding

Run-time polymorphism is known as overriding. Overriding is achieved by using a function keyword that is virtual. This keyword is used in base class. When derived class redefine a function, the overridden function cannot be changed. Overriding in C++ determines that which version of the function is called.

Key Differences

  1. Function overloading in C++ is compile-time polymorphism whereas Function overriding in C++ is run-time
  2. There is a specific keyword in overloading whereas “Virtual” is a specific keyword in function overriding.
  3. In overloading function, there is compile time accomplishment whereas in function overriding there is a run-time
  4. In function overloading there is early binding whereas in function overriding there is late binding
Advertisement - Continue Reading Below

Conclusion

In this article above we see the clear difference between function overloading and function overriding with examples.

Explanatory Video

Leave a Comment