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
What is the main purpose of inheritance law?
What is inheritance and how many types of inheritance?
What is data binding in oops?
How is polymorphism achieved?
Can a varargs method be overloaded?
write a program to find 2^n+1 ?
hi all..i want to know oops concepts clearly can any1 explain??
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?
What do you mean by Encapsulation?
Is data hiding and abstraction same?
Why do we use encapsulation in oops?
hi, this is raju,iam studying b.tech 2nd year,iam want know about group1 and group2 details, and we can studying without going to any instutions? please help me.
What is overriding in oops?
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?
How many human genes are polymorphic?