我遇到代碼問題。錯誤C2664:'way':無法將參數4從'int'轉換爲'int&'
這是我的主要。
int main()
{
cin>>xG>>yG;
int x,y;
cin>>x>>y;
int crrWay[200] = {0},
minWay[200] = {0},
minWayN = -1;
way(x, y, crrWay, 0, 0, minWay, minWayN, 0);
printWay(minWay, minWayN);
return 0;
}
這是函數。
void way(int x, int y, int *crrWay, int& crrWayWeight, int l, int* minWay, int& minWayN, int& minWayWeight)
{
crrWay[2*l] = x;
crrWay[2*l+1] = y;
if(x < 0 || y < 0 || x > 10 || y > 10)
return;
// Сравнява намерения път с минималния
if(x == xG && y == xG)
{
registerWay(crrWay, l+1, minWay, minWayN, crrWayWeight, minWayWeight);
return;
}
// Клетката е непроходима.
if(tempMaze[x][y]==0)
return;
tempMaze[x][y] = 0;
crrWayWeight+=maze[x][y];
// Рекурсивни обръщения към всеки от четирите съседа
way(x+1, y, crrWay, crrWayWeight, l+1, minWay, minWayN, minWayWeight);
way(x, y+1, crrWay, crrWayWeight, l+1, minWay, minWayN, minWayWeight);
way(x-1, y, crrWay, crrWayWeight, l+1, minWay, minWayN, minWayWeight);
way(x, y-1, crrWay, crrWayWeight, l+1, minWay, minWayN, minWayWeight);
// връщане назад
tempMaze[x][y] = 1;
}
代碼無法編譯。它說
1> C:\用戶\管理員\文件\ zad51.cpp(102):錯誤C2664: '方式':不能 轉換參數4從 'INT' 到 'INT &'
爲什麼你能夠傳入字面值作爲參考?這個不成立。 – chris