Write an operator overloading program to write S3+=S2.
Answers were Sorted based on User's Feedback
Answer / 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 |
how to find no of instances of an object in .NET?
What is virtual constructors/destructors?
Do you know about multiple inheritance?
what is opps?why it is use in programming language?
Why do we need polymorphism in c#?
Why do we need oop?
What is protected in oop?
Describe what an Interface is and how it?s different from a Class.
What is operator overloading? Give Example
11 Answers CTS, IBM, TCS,
IS IT NECESSARY TO INITIALIZE VARIABLE? WHAT IF THE INSTANCE VARIABLE IS DECLARED final ? IS IT NECESSARY TO INITIALIZE THE final VARIABLE AT THE TIME OF THEIR DECLARATION?
what i oops concept, how many languages supports oops concept?
What is design patterns in C++?