代码整理,将学过的三种运算符重载,每个至少实现一个运算符的重载
#include <iostream>
using namespace std;
class Cloudy
{
friend bool operator!=(const Cloudy &L,const Cloudy &R);
private:
int a;
public:
int b;
public:
Cloudy(){}
Cloudy(int a,int b):a(a),b(b)
{}
const Cloudy operator*(const Cloudy &R)const
{
Cloudy temp;
temp.a = a * R.a;
temp.b = b * R.b;
return temp;
}
Cloudy operator*=(Cloudy &R)
{
a *= R.a;
b *= R.b;
return *this;
}
void show()
{
cout << "a =" << a << " " << "b =" << b << endl;
}
};
bool operator!=(const Cloudy &L,const Cloudy &R)
{
if(L.a != R.a || L.b != R.b)
{
return true;
}
else
{
return false;
}
}
int main()
{
Cloudy c1(11,45);
Cloudy c2(14,45);
Cloudy c3;
c3 = c2 * c1;
c3.show();
if(c1 != c2)
{
cout << "c1 != c2" << endl;
}
c3 *= c1;
c3.show();
return 0;
}