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

Do you know about multiple inheritance?

637


What do you mean by variable?

572


What are the types of abstraction?

551


What is destructor oops?

617


What is protected in oop?

600






Why do we use inheritance?

628


What is encapsulation process?

575


Is this job good for future? can do this job post grduate student?

1689


What is the difference between encapsulation and polymorphism?

589


Which is better struts or spring?

615


What is destructor give example?

598


What does and I oop mean?

610


Plese get me a perfect C++ program for railway/airway reservation with all details.

3427


which feature are not hold visual basic of oop?

1721


What do you mean by abstraction?

608