Write an operator overloading program to write S3+=S2.

Answer Posted / som shekhar

class A
{
int id;

public:
A& operator +(const A& a1)
{
A a;
a.id = id + a1.id;
return a;
}
A & operator =(const A& a1)
{
if( this == &a1)
return;
else
{
A a;
a.id = a1.id;
return a;

}
}
};


S3 += S2 internaly will be called as
S3->operator=(s3->operator+(s2));

In this case first + operator will be called and then
assignment operator will be called.

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you define social class?

798


what is the sylabus for priliminaries?

1891


What is oops concept with example?

761


Write a program to sort the number with different sorts in one program ??

2102


What is polymorphism explain its types?

904


Why is static class not inherited?

814


Please send ford technologies placement paper 2 my mail id

1837


What is interface in oop?

871


What is encapsulation with real life example?

779


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

1830


What is multilevel inheritance?

935


What is object and class in oops?

777


write string class as your own class in java without using any built-in function

2198


program for insertion ,deletion,sorting in double link list

2435


Why do we need polymorphism in c#?

872