gpt4 book ai didi

c++ - 函数无法识别我在 C++ 中传递节点指针 vector ?

转载 作者:行者123 更新时间:2023-12-02 10:07:44 24 4
gpt4 key购买 nike

我对 C++ 很陌生,对于二叉树项目,我试图将节点指针 vector 传递给将添加/操作树的函数。错误在下面注释。

函数签名之一的示例:

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 所指出的,这些函数,或者至少它们的原型(prototype),需要在它们被调用之前出现。

关于c++ - 函数无法识别我在 C++ 中传递节点指针 vector ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59314119/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com