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 the 3 types of system development life cycle

2431


Write a c++ program to display pass and fail for three student using static member function

2812


What is the use of oops?

619


What are the components of marker interface?

600


Prepare me a program for the animation of train

1994






hi all..i want to know oops concepts clearly can any1 explain??

1681


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’.

1778


Which is better struts or spring?

616


They started with the brief introduction followed by few basic C++ questions on polumorphism, inheritance and then virtual functions. What is polymorphims? How you will access polymorphic functions in C? How virtual function mechanism works?

1403


What is abstraction example?

616


What are the data types in oop?

602


officer say me - i am offered to a smoking , then what can you say

1578


write a program using c++ to implement single contiguous memory mangement techniques.display the content of the main memory after yhe allocation of jobs and percentage of the wastage of the main memory

2754


Why do we use oop?

603


What is difference between data abstraction and encapsulation?

613