我试图用一个简单的结构,地图键:重载<运算符类内部
class Foo{
.
.
.
struct index{
int x;
int y;
int z;
};
bool operator<(const index a, const index b);
.
.
.
}
而且功能itslef:
bool Foo::operator<(const index a, const index b){
bool out = True;
if (a.x == b.x){
if (a.y == b.y){
if (a.z >= b.z) out = false;
}
else if(a.y > b.y) out = false;
} else if (a.x > b.x) out = false;
return out;
}
然而,当我编译错误:
memMC.h:35: error: 'bool Foo::operator<(Foo::index, Foo::index)' must take exactly one argument
据我了解这一点,编译器要比较index
这个Foo
。那我该如何超载操作员呢?
谢谢!这个问题在过去的几个小时里一直困扰着我。我没有想到修复会如此简单。 – Dennis 2012-05-04 22:36:33