我改变了我的列表(和代码),所以它现在处理Node*而不是Node Objects,这导致了一个未定义的引用错误
c++ i change my list(and code) so it now handles Node* rather than Node Objects and it has caused an undefined reference error
我试图在c++中做一个a *,但我有一个解决方案后的路径问题。我的老师建议我使用Node*并使用new在堆上创建它们,因为我的旧的是在堆栈上分配它们,显然你不应该在堆栈上返回指针,所以它在运行时弄乱了代码。
我遇到的问题是,当我改变我的列表保持,而不是我得到这个错误:
undefined reference to `checkInClosedList(std::vector<Node*, std::allocator<Node*> >, int, int)'
undefined reference to `placeInOpen(std::list<Node*, std::allocator<Node*> >, int, int)'
当我调用这些函数时:
if(placeInOpen(openList,best->getX()-1, best->getY())){
//do something
}
if(!checkInClosedList(closedList, best->getX(), best->getY())){
// do something
}
给出best和openList的代码:
list<Node*> openList;
vector<Node*> closedList;
Node *end;
Node *start = initiateStart(map);
openList.push_front(start);
while (!openList.empty()) {
Node *best = openList.front();
openList.pop_front();
}
//some other logic.....
函数在头文件中定义如下:
bool placeInOpen(std::list<Node*>& v,int x, int y);
bool checkInClosedList(std::vector<Node*>& v, int x, int y);
在我编辑我的函数和列表以包含Node*这工作得很好,为什么它对指针不同(我已经正确处理了指针操作,只是这个错误导致我头痛)
欢呼,克里斯。
您已经将函数声明更改为新类型,但是您还必须更改定义。
然而,我建议你根本不要做这个更改;你的老师似乎在胡说八道。Node
对象在列表中,而不是"在堆栈上",它们的生命周期由列表正确管理。存储动态对象的指针会导致内存泄漏,甚至更糟。
bool checkInClosedList(std::vector<Node*>& v, int x, int y);
只是一个前向声明。它告诉编译器在其他地方期望具有该签名的函数的工作实现。你必须在你的函数实现中改变它
相关文章:
- node-gyp 在 macOS 上未正确链接库
- 为什么C++对链表中的下一个节点使用指针,而像 C# 或 Java 这样的语言只使用类 Node 的名称?
- node-gyp 的先有鸡还是先有蛋的问题:指向依赖项中的头文件
- 在 ubuntu 上安装 node js pulsar 客户端
- 如何使用 Node-addon-API 实现 node-nan 回调
- Node.js fs.open() 在尝试打开 4 个以上的命名管道 (FIFO) 后挂起
- NodeJS:node-gyp 编译与等效的 gcc -lm 选项
- 调用'Node'构造函数是不明确的
- 为什么我得到变量"Node"不是类型名称错误
- 在 node.js 中将缓冲区从 C++ 转换为 UTF-8 字符串
- 如何从 node-ffi 调用 c++ 中以结构向量作为参数的方法?
- 使用 Node.js N-API 调用 C 函数时,不会显示预期的输出
- 给一个图 G 找到此图中的所有节点 blob,以便 node.color 属性 = 特定颜色
- 为什么 const YAML::Node 对象的行为不像 yaml-cpp 中的类似值的对象?
- 无法使用 'const Node *' 类型的右值初始化 'Node *' 类型的变量
- Node中的子节点列表在C++中的BFS遍历过程中丢失
- 用输出参数包装一个c++函数,以便在javascript/node中使用
- 在node-gip binding.gyp文件中,如何根据系统结构(32位、64位)包含不同的库文件
- node.h/node.cpp/nodelist.cpp之间的关系
- 我改变了我的列表(和代码),所以它现在处理Node*而不是Node Objects,这导致了一个未定义的引用错误