[英]Error C2440: 'return' : cannot convert from 'int [2]' to 'int (&&)[2]'
我已经有一段时间没有编程了,所以我的代码可能有点草率。 程序唯一要做的就是创建一个4x4 bool网格,其中左上角的值均为true。 然后,它使用checkAdjacentTiles运行它,它应该返回与之接触的图块(右边的一个和下面的一个)。 我得到一个错误。 我感觉这与我的向量有关: std::vector<int[2]> checkAdjacentTiles(bool[4][4]);
,因为int [2]。 谢谢您的帮助!
#include <stdio.h>
#include <vector>
std::vector<int[2]> checkAdjacentTiles(bool[4][4]);
int main() {
bool grid[4][4];
grid[0][0] = 1;
std::vector<int[2]> temp = checkAdjacentTiles(grid);
for (int i = 0; i < (int)temp.size(); i++) {
printf("(%i, %i)\n", temp[i][0], temp[i][1]);
}
getchar();
return 0;
}
std::vector<int[2]> checkAdjacentTiles(bool checkGrid[4][4]) {
int relAdjacentSides[4][2] = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 } };
std::vector<int[2]> adjacentSides;
for (int x = 0; x < 4; x++) {
for (int y = 0; y < 4; y++) {
for (int i = 0; i < 4; i++) {
if (x + relAdjacentSides[i][0] >= 0 && x + relAdjacentSides[i][0] < 4) {
if (y + relAdjacentSides[i][1] >= 0 && y + relAdjacentSides[i][1] < 4) {
if (!checkGrid[x + relAdjacentSides[i][0], y + relAdjacentSides[i][1]]) {
bool stop = 0;
for (int v = 0; v < (int)adjacentSides.size(); v++) {
if (adjacentSides[v][0] == x + relAdjacentSides[i][0] && adjacentSides[v][1] == y + relAdjacentSides[i][1]) {
stop = 1;
break;
}
}
if (!stop) {
adjacentSides.push_back({ x + relAdjacentSides[i][0], y + relAdjacentSides[i][1] });
}
}
}
}
}
}
}
return adjacentSides;
}
由于某种原因,我无法在向量中使用int[2]
。 我最终使用了std::pair<int,int>
,它工作正常。 谢谢jhnnslschnr。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.