在 VS 2015 中编译程序时出现错误:
call of an object of a class type without appropriate operator() or conversion functions to pointer-to-function type
它用红色标记函数调用,它返回一个 vector 。这是代码:
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”的调用。
最佳答案
vector<punct> shag(int x, int y, int nrShaga) {
punct shag;
局部变量 shag
与函数同名。
关于c++ - 如何从返回 vector 的函数中获取 vector 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37771538/