#include <iostream>
#include <cmath>
using namespace std;
class com
{
public:
com(){a = 0;}
com(int x):a(x){};
friend com operator + (com &c1, com &c2);
friend com operator - (com &c1, com &c2);
com operator ++();
com operator ++(int);
friend bool operator !=(com &c1, com &c2);
friend bool operator ==(com &c1, com &c2);
com operator = (com &c2);
void display();
~com(){cout<<"析构函数"<<endl;}
private:
int a;
};
com operator + (com &c1, com &c2)
{
com c;
c.a = c1.a+c2.a;
cout<<"c1+c2 = "<<c.a<<endl;
return c;
}
com operator - (com &c1, com &c2)
{
com c;
c.a = c1.a-c2.a;
cout<<"c1-c2 = "<<c.a<<endl;
return c;
}
com com::operator ++()
{
++a;
return *this;
}
com com::operator++(int)
{
a++;
return *this;
}
bool operator !=(com &c1, com &c2)
{
if(c1.a!=c2.a)
return 1;
else
return 0;
}
bool operator ==(com &c1, com &c2)
{
if(c1.a==c2.a)
return 1;
return 0;
}
com com :: operator = (com &c2)
{
a = c2.a;
return *this;
}
void com::display()
{
cout<<a<<endl;
}
int main()
{
com c1(5), c2(1);
com c3 = c1+c2;
com c4 = c1-c2;
if(c1==c2)
cout<<"c1==c2"<<endl;
else if(c1!=c2)
{
cout<<"c1!=c2"<<endl;
c1++;
cout<<"c1++"<<endl;
cout<<"c1 = ";c1.display();
++c1;
cout<<"++c1"<<endl;
cout<<"c1 = ";c1.display();
}
c2 = c1;
cout<<"c2 = c1"<<endl;
cout<<"c1 = ";c1.display();cout<<"c2 = ";c2.display();
return 0;