#include<iostream>
using namespace std;
class A
{
int a;
public:
A(int x=0):a(x){
cout<<"in Cons"<<endl;
}
friend A operator+(const A& _a1, const A& _a2);
friend ostream& operator<<(ostream &out, const A& _a);
int getData()
{
return a;
}
};
A operator+(const A& _a1, const A& _a2)
{
cout<<"Inside operator+"<<endl;
return A(_a1.a + _a2.a);
}
ostream& operator<<(ostream & o, const A& _a)
{
o << _a.a;
return o;
}
int main()
{
A x1(2), x2(3);
A x3 = x1 + x2;
cout << x3 <<", "<<x1<<endl;
}
using namespace std;
class A
{
int a;
public:
A(int x=0):a(x){
cout<<"in Cons"<<endl;
}
friend A operator+(const A& _a1, const A& _a2);
friend ostream& operator<<(ostream &out, const A& _a);
int getData()
{
return a;
}
};
A operator+(const A& _a1, const A& _a2)
{
cout<<"Inside operator+"<<endl;
return A(_a1.a + _a2.a);
}
ostream& operator<<(ostream & o, const A& _a)
{
o << _a.a;
return o;
}
int main()
{
A x1(2), x2(3);
A x3 = x1 + x2;
cout << x3 <<", "<<x1<<endl;
}
No comments:
Post a Comment