【发布时间】:2015-04-14 00:54:50
【问题描述】:
我正在使用斯坦福的 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 的行和列分配给它们各自的变量。 然后它循环遍历每一行,从比传递的行少一个开始,到多一个 列也是如此。但是,我相信我正在比较 for 循环中的整数,但它说我正在比较 dieLocations?有谁知道为什么会这样?
【问题讨论】:
-
如果
Set与std::set类似,则为有序。 -
Set可能使用operator<对其元素进行排序。如果是这样,请在dieLocation上定义operator<重载。
标签: c++ qt for-loop match operand