cpp
#include <iostream>
#include <string>
using namespace std;
class Students06{
public:
string m_name;
int m_age;
Students06(string name, int age){
this->m_name = name;
this->m_age = age;
}
// 重载了 ==
bool operator==(Students06 &stu){
if(this->m_name == stu.m_name && this->m_age == stu.m_age){
return true;
}
else{
return false;
}
}
// 重载了 !=
// this->m_name == stu.m_name && this->m_age == stu.m_age 词语会自动返回 true 或 false
bool operator!=(Students06 &stu){
return !(this->m_name == stu.m_name && this->m_age == stu.m_age);
}
};
int main()
{
// int a = 10;
// int b = 20;
// if(a==b)
// {
// cout << "a==b" << endl;
// }
// else{
// cout<< "a != b" << endl;
// }
Students06 stu1("四",18);
Students06 stu2("五",18);
// if(stu1 == stu2){
// cout << "stu1 == stu2"<< endl;
// }
// else{
// cout << "stu1 != stu2"<< endl;
// }
if(stu1 != stu2){
cout << "stu1!=stu2"<< endl;
}
else{
cout<< "stu1 == stu2" << endl;
}
return 0;
}