Difference between Operator overloading and Functional
overloading?
Answer Posted / swetcha
Function overloading is like you have different functions
with the same name but different signatures working
differently. So, the compiler can differentiate and find
out which function to call depending on the context. In
case of operator overloading, you try to create your own
functions which are called when the corresponding operator
is invoked for the operands.
One important thing to understand is that you can create as
many functions as you want with the same name and sifferent
signatures so that they can work diffrently but for a
particular class, you cannot overload the operator function
based on number of arguments. There is a fundamental reason
behind this.
According to the rules, you can not create your own
operators but you have to use already available operators.
Another thing is since the operator are already defined for
use with buily-in types you can not change their
charecteristics. For example the binary operator '+' always
takes two parameters, so for this you cannot create a
function that takes three parameters. But you can always
overload them based on the type of the parameters.
| Is This Answer Correct ? | 115 Yes | 14 No |
Post New Answer View All Answers
What is an adaptor class in c++?
What do you mean by function overriding & function overloading in c++?
What is main function in c++ with example?
Can we make copy constructor private in c++?
What is a constructor in c++ with example?
What is object in c++ example?
What is wrapper class in c++?
What is the role of C++ shorthand's?
If dog is a friend of boy, and terrier derives from dog, is terrier a friend of boy?
What are the uses of c++ in the real world?
Define namespace in c++?
What are pointer-to-members in C++? Give their syntax.
Why do we need constructors in c++?
Explain the difference between using macro and inline functions?
What is the keyword auto for?