在VS 2015中编译程序时出错:
调用类类型的对象而没有适当的operator()或转换函数到指向函数类型
它标记为红色调用函数,它返回一个向量。这是代码:
struct punct {
int x, y, val;
};
int koli4estvoShagov = 0;
int arr[100][100];
int n, m;
vector<punct> shag(int x, int y, int nrShaga) {
punct shag;
shag.val = arr[x][y];
shag.x = x;
shag.y = y;
vector<punct> shagi;
shagi.push_back(shag);
if (nrShaga == koli4estvoShagov - 1) {
return shagi;
}
else if (x == m - 1) {
vector<punct> shagVNiz = shag(x, y + 1, nrShaga + 1);
shagi.insert(shagi.end(), shagVNiz.begin(), shagVNiz.end());
return shagi;
}
else if (y == n - 1) {
vector<punct> shagVPravo = shag(x + 1, y, nrShaga + 1);
shagi.insert(shagi.end(), shagVPravo.begin(), shagVPravo.end());
return shagi;
}
else {
vector<punct> shagVPravo = shag(x + 1, y, nrShaga + 1);
vector<punct> shagVNiz = shag(x, y + 1, nrShaga + 1);
vector<punct> max;
if (sum(shagVNiz) > sum(shagVPravo))
max = shagVNiz;
else
max = shagVPravo;
shagi.insert(shagi.end(), max.begin(), max.end());
return shagi;
}
}
具体看看对函数“shag”的调用。
答案 0 :(得分:2)
vector<punct> shag(int x, int y, int nrShaga) {
punct shag;
局部变量shag
与函数名称相同。