自定义 < 和 != 就可利用命名空间引用rel_ops
#include <iostream>
using namespace std;
class Integral
{
public:
Integral(int i):ig(i){}
bool operator ==(const Integral& rhs)const
{
return ig == rhs.ig;
}
bool operator < (const Integral& rhs)const
{
return ig < rhs.ig;
}
private:
int ig;
};
int main()
{
using namespace rel_ops;
Integral a(5), b(6),c(5);
if (a < b)
{
cout << "called our definition operator < " << endl;
}
if (a == b)
{
cout << "called our definition operator == " << endl;
}
if (b > a)
{
cout << "called make by rel_pos operator > " << endl;
}
if (b != a)
{
cout << "called make by rel_pos operator != " << endl;
}
system("pause");
return 0;
}