函数无法识别我在 C++ 中传递的节点指针向量?
Function is not recognizing me passing a vector of node pointers, in C++?
我是 C++ 的新手,对于一个二叉树项目,我试图将一个节点指针向量传递给一个将 add/manipulate 树的函数。错误在下面评论。
函数签名之一的示例:
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;
}
如果这些函数与您的 "Main code" 不在同一个文件中,请确保它们可以通过某种方式显示 include
。
编辑:正如@QuentinUK 所指出的,这些函数,或者至少是它们的原型,需要在调用之前出现。
我是 C++ 的新手,对于一个二叉树项目,我试图将一个节点指针向量传递给一个将 add/manipulate 树的函数。错误在下面评论。
函数签名之一的示例:
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;
}
如果这些函数与您的 "Main code" 不在同一个文件中,请确保它们可以通过某种方式显示 include
。
编辑:正如@QuentinUK 所指出的,这些函数,或者至少是它们的原型,需要在调用之前出现。