why to use operator overloading

Answer Posted / chandra

to achieve synchronization with the normal languages like c.
for example int a=10,b=30,c;
c = a+b ;
the above operation is possible in c as well as c++.bcos
the variables declared are primitive types.

If u want to do same thing for user defined datatypes, i
can say objects, we have to overload the operators.

For ex:
Assume that u created one class
Class A
and u have created objects
A obj1(10),obj2(30),obj3;

and u want the add 2 objects and result must be stored in
another object.

then u have to overload the operator + for class A.

obj3 = obj1 + obj2 ;

Is This Answer Correct ?    7 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is polymorphism and types?

608


How do you achieve runtime polymorphism?

575


Describe these concepts: Polymorphism, Inheritance and Abstraction.

622


What is persistence in oop?

677


Why do while loop is used?

583






How to hide the base class functionality in Inheritance?

650


Why do pointers exist?

669


INSTANCE FIELDS DECLARED private ARE ACCESSIBLE BY THE METHODS ONLY.CAN WE CHANGE THE private FIELD OF AN OBJECT IN A METHOD OF SOME OTHER OBJECT OF THE SAME CLASS?

1639


What is polymorphism and example?

598


What is the point of polymorphism?

598


What is use of overloading?

618


What exactly is polymorphism?

616


Can you explain polymorphism?

590


Can enum be null?

594


Which is better struts or spring?

627