与'operator<'错误不匹配。C++
Getting no match for 'operator<' error. C++
我有一个项目正在斯坦福大学的CS106B上进行,这太不可思议了。我有一个结构,dieLocation,它应该代表我的Boggle板上的一个骰子的位置。
typedef struct dieLocation {
int row, column;
}dieLocation;
然后我有了这个代码:
Set<dieLocation> Boggle::getUnmarkedNeighbors(Grid<bool> &markedLocations, dieLocation currentDie) {
int row = currentDie.row;
int column = currentDie.column;
Set<dieLocation> neighbors;
for(int currRow = row - 1; currRow < row + 1; currRow++) {
for(int currCol = column - 1; currCol < column + 1; currCol++) {
//if neighbor is in bounds, get its row and column.
if(markedLocations.inBounds(currRow, currCol)) {
//if neighbor is unmarked, add it to the neighbors set
if(markedLocations.get(currRow, currCol)) {
dieLocation neighbor;
neighbor.row = currRow;
neighbor.column = currCol;
neighbors.add(neighbor);
}
}
}
}
return neighbors;
}
我试图在Qt Creator中构建这个项目,但我一直收到一个错误,它是:"operator<"不匹配(操作数类型为常量dieLocation和常量dieLocation)
我的代码所做的是,它将传递的dieLocation的行和列分配给它们各自的变量。然后,它循环遍历每一行,从比传递的行少一行开始,到多一行列也是如此。然而,我相信我在for循环中比较整数,但它说我在比较dieLocations?有人明白为什么会发生这种事吗?
operator <
在Set
内部用于订购其物品。您应该为struct dieLocation
定义它。例如:
inline bool operator <(const dieLocation &lhs, const dieLocation &rhs)
{
if (lhs.row < rhs.row)
return true;
return (lhs.column < rhs.column);
}
相关文章:
- Qt SQLite没有查询或参数计数不匹配
- 模板参数推导失败,函数参数/参数不匹配
- 在使用累加时,C++中的运算符+不匹配
- C++ 与操作员不匹配<<
- 在 Arduino 上使用 sscanf 会导致与 const char * 不匹配,并且返回值始终相同,尽管输入值不同
- 与'operator='不匹配(操作数类型'String'且"void")
- C++模板/别名 - 模板参数列表中参数 1 处的类型/值不匹配
- C4018:类内有符号、无符号不匹配
- 我在 .h 中有一个枚举类,并且在.cpp错误中有一个运算符重载:与"运算符<<不匹配
- 为什么我收到错误:"运算符<<不匹配?
- RE2 不匹配非 ASCII 字符
- 函数签名与调用的函数不匹配,常量字符[]和字符*之间的区别?
- 模板推导:为什么函数指针模板定义在常量和/或引用时不匹配?
- 错误:"模板<类_Tp,类_Dp>类 std::unique_ptr"的模板参数列表中参数 1 的类型/值不匹配
- OpenSSL fips in C++ wrapper Library 如何?错误:指纹不匹配
- 为什么我的数组值与此处的全局变量不匹配?
- 引号之间匹配/不匹配,带有不可避免的引号和多行
- 映射迭代器与运算符不匹配
- C++调用和定义不匹配
- 模板专用化与派生类不匹配