我对C++很陌生,对于二叉树项目,我正在尝试将节点指针向量传递到将添加/操作树的函数中。错误注释如下。
函数签名之一的示例:
void add(vector <Node*> &nodes, int &Aindex, vector <int> A, int value, vector <int> E, int Eindex);
主代码:
vector <Node*> makeTree(vector <int> A, vector <int> E) {
vector <Node*> nodes = {};
int Aindex = 0;
for (int i = 0; i < E.size(); i++) {
if (i == 0 || i % 2 != 0) {
if (i == 0) {
create(nodes, Aindex, A, E[i]); // no matching function to call to ERROR.
} else {
add(nodes, Aindex, A, E[i], E, i); // no matching function to call to ERROR.
}
Aindex++;
} else {
if (find(nodes, Aindex, A, E[i]) == false) { // no matching function to call to ERROR.
create(nodes, Aindex, A, E[i]); // no matching function to call to ERROR.
Aindex++;
} else {
}
}
}
return nodes;
}
确保,如果这些函数与"主代码"不在同一文件中,则它们可以通过某种include
可见。
编辑:正如@QuentinUK所指出的,这些函数,或者至少是它们的原型,需要在调用它们之前出现。