#include <iostream>
using namespace std;
class A {
private:
int x;
public:
A(int y) { x = y; }
bool operator < (const A& a) {
if (x < a.x)
return true;
else
return false;
}
};
int main()
{
A a(1);
A b(2);
if (a < b) //两个类做比较
cout << "yes" << endl;
else
cout << "NO" << endl;
return 0;
}
关系运算符重载 在要重载的类型 (类或者结构体中 写重载函数)