Expression:invalid operator

#include
#include <map>
using namespace std;


/*
** 測試目的:重現斷言,"include\xtree Line:1746 Expression:invalid operator<"。
** 重現手法:operator<都返回true
** 結論:map[key] = value.key重複是不會導致以上斷言,而是比較函數寫法錯誤
*/
struct Test
{
public:
bool operator<(const Test& token) const
{
if (value < token.value) {
return true;
} else {
return true; // 注意,都是true
}
}


public:
long value;
};


void main()
{
Test t1, t2;
t1.value = 1;
t2.value = 2;
map<Test, long> mapValues;
mapValues[t1] = 1;
mapValues[t2] = 2;
int i = 0;
cin >> i;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章