Question:
whats the difference b/w function overloading and function overiding in cpp?
Venki
2006-05-10 01:36:55 UTC
whats the difference b/w function overloading and function overiding in cpp?
Three answers:
Nand Kishore
2006-05-10 01:52:46 UTC
Function Overloading:



Function Overloading means using the same function name for more than one function, but the functions signature must differ. Funtion Signature means - the no. of parameters, the type of parameters and/or sequence of parameters passed. For example, the following function will be called as overloaded:



void Add(int,int);

void Add(int,float);

void Add(float,int);

void Add(int, int, int);



For all these functions, either the no of parameters are different or the type or the sequence is different.



Look at the following functions:



void Add(int, int);

int Add(int, int);



These functions are not overloaded as the signature of the functions are same, only the return type is different. If you compile this, you will get error message.



Function Overiding:

==================



Function Overiding is the process of redefining the base class function in its derived class. This can be used if you are using classes and you want to change the functinality of the base class function in the derived class. Ex:



class base

{

void add()

{

cout<<"Add";

}

}



class d:public A

{

void add()

{

cout<<"Derived";

}

}



Function add() is said to be overidden in the derived class d.
hrushi
2006-05-10 08:43:34 UTC
Function overloading means having the same function name performing different functions based on arguments.



Function overriding means redefining the function in one the child class.
coolgirl
2006-05-10 09:02:09 UTC
overloading:Overloading allows multiple functions taking different types to be defined with the same name; the compiler or interpreter automatically calls the right one.

overriding:it is the opposite of the former


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...