What is function overloading and operator overloading?

Answer Posted / sagar sapkota

A function is overloaded when same name is given to different function. However, the two functions with the same name will differ at least in one of the following.

a) The number of parameters
b) The data type of parameters
c) The order of appearance

These three together are referred to as the function signature.

For example if we have two functions :

void foo(int i,char a);
void boo(int j,char b);

Their signature is the same (int ,char) but a function

void moo(int i,int j) ; has a signature (int, int) which is different

While overloading a function, the return type of the functions need to be the same.

In general functions are overloaded when :

1. Functions differ in function signature.
2. Return type of the functions is the same.

Operator overloading allows existing C++ operators to be redefined so that they work on objects of user-defined classes. Overloaded operators are syntactic sugar for equivalent function calls. They form a pleasant facade that doesn't add anything fundamental to the language (but they can improve understandability and reduce maintenance costs).

Is This Answer Correct ?    8 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is polymorphism in oop example?

525


Can we create object of abstract class?

585


State what is encapsulation and friend function?

710


What is difference between multiple inheritance and multilevel inheritance?

610


What are the benefits of oop?

613






i am getting an of the type can not convert int to int *. to overcome this problem what we should do?

1847


What is methods in oop?

561


What do you mean by Encapsulation?

651


What is pointer in oop?

543


What is abstraction encapsulation?

667


Why do we use polymorphism in oops?

593


class CTest { public: void someMethod() { int nCount = 0; cout << "This is some method --> " << nCount; } }; int main() { CTest *pctest; pctest->someMethod(); return 0; } It will executes the someMethod() and displays the value too. how is it possible with our creating memory for the class . i think iam not creating object for the class. Thanks in Advance... Prakash

1706


What is destructor in oop?

631


What is advantage of inheritance?

696


What is polymorphism programming?

611