我用dev c++ 执行如下代码:
#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
struct posn
{
int x,y,dis;
bool operator < (const posn& b)const{
return dis<b.dis;
}
};
map<posn,bool>vis;
int main()
{
posn test;
test.x=1; test.y=1; test.dis=1;
cout<<vis[test]<<endl;
vis[test]=true;
cout<<vis[test]<<endl;
test.x=2;
cout<<vis[test]<<endl;
}
得到输出结果
0
1
1
我不明白为什么x=2的test对应的value也会变成1;
我注意到也许这和结构体中的重载运算符有关,但是具体原理我就搞不清楚了,求各位解答。