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.
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.
Comparison Chart
Basis | Overloading | Overriding |
Meaning | Function overloading in C++ is compile-time polymorphism |
Function overriding in C++ is a run-time polymorphism.
|
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 binding | In 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 between Function Overloading and Overriding in C++
- Function overloading in C++ is compile-time polymorphism whereas Function overriding in C++ is run-time
- There is a specific keyword in overloading whereas “Virtual” is a specific keyword in function overriding.
- In overloading function, there is compile time accomplishment whereas in function overriding there is a run-time
- In function overloading there is early binding whereas in function overriding there is late binding
Conclusion
In this article above we see the clear difference between function overloading and function overriding with examples.