Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differentiate between function overloading and function overriding

Differentiate between function overloading and function overriding in C++?

like image 473
Amol Joshi Avatar asked Aug 11 '12 04:08

Amol Joshi


People also ask

What is difference between function overloading and function overriding?

Function overloading is used when we want multiple functions providing similar implementation. However, function overriding is used when we want to add some additional functionality on top of base class implementation.


1 Answers

Overloading a method (or function) in C++ is the ability for functions of the same name to be defined as long as these methods have different signatures (different set of parameters). Method overriding is the ability of the inherited class rewriting the virtual method of the base class.

a) In overloading, there is a relationship between methods available in the same class whereas in overriding, there a is relationship between a superclass method and subclass method.

(b) Overloading does not block inheritance from the superclass whereas overriding blocks inheritance from the superclass.

(c) In overloading, separate methods share the same name whereas in overriding, subclass method replaces the superclass.

(d) Overloading must have different method signatures whereas overriding must have same signature.

like image 117
Prasad G Avatar answered Sep 22 '22 01:09

Prasad G