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
What is the difference between encapsulation and polymorphism?
write a code for this. serial_number contained in the header of the file will be read , if this serial number is less than a previous serial number within a successfully processed file, or is the same as another serial number within a successfully processed file, or if the field contains anything other than 7 digits, then the file must error with the reason ‘Invalid SERIAL_NUMBER’.
Why is it so that we can have virtual constructors but we cannot have virtual destructors?
How do you use inheritance in unity?
Can abstract class have normal methods?
What exactly is polymorphism?
what is difference between class template and template class?
What does and I oop and sksksk mean?
Why oops is important?
what are the different types of qualifier in java?
What is polymorphism and types?
Why do we use polymorphism?
What is cohesion in oop?
program for insertion ,deletion,sorting in double link list
What is abstraction and encapsulation?