我有由 3 个整数的组合唯一标识的数据。
例如:
项目 #1:10,20,1
项目 #2:10,21,0
项目 #3:0,14,13
项目 #4:103,324,78
我的结构:
struct structureKeyID
{
int keyA;
int keyB;
int keyC;
// Comparison operator for table sorting.
bool operator<(const structureKeyID& param) const
{
if (keyA < param.keyA) return true;
if (keyB < param.keyB) return true;
if (keyC < param.keyC) return true;
return false;
}
};
map <structureKeyID, classDataRecord> tableRecords;
我发现如果我添加一个键(0,0,1):
structureKeyID keyID1;
keyID1.keyA = 0;
keyID1.keyB = 0;
keyID1.keyC = 1;
tableRecords[keyID1] = <data>;
然后我检查键 (0,1,0) 是否存在:
structureKeyID keyID2;
keyID1.keyA = 0;
keyID1.keyB = 1;
keyID1.keyC = 0;
if (tableRecords.find(keyID2) != tableRecords.end())
然后我会得到一个错误:
调试断言失败!
\include\xtree 行:1268
表达式:无效的运算符
然而,如果我检查 key (0,0,2) 或 key (10,0,2) 是否存在,它工作正常。
针对这种情况构建比较运算符的正确方法是什么?
非常感谢!