关系运算符重载
#include<iostream>
using namespace std;
class wood {
public:
int num;
int height;
//==运算符重载
bool operator==(wood w)
{
if (num == w.num && height == w.height)
{
return true;
}
return false;
}
//!=运算符重载
bool operator!=(wood w)
{
if (num != w.num || height != w.height)
{
return true;
}
return false;
}
};
void test()
{
wood w1;
w1.num = 100;
w1.height=10;
wood w2;
w2.num = 100;
w2.height = 11;
if (w2 == w1)
{
cout << "w1和w2相等" << endl;
}
if(w2!=w1)
{
cout << "w1和w2不相等" << endl;
}
}
int main()
{
test();
return 0;
}