尝试引用已删除的函数(不引用函数)
Attempting to reference a deleted function (No reference to a funciton made)
我现在遇到了一个问题,显然我正在Attempting to reference a deleted function
.据我所知,我实际上并不是在引用函数,而是指向结构的智能指针。
这是一个大学项目,其中使用多个头文件和CPP文件,使我们能够了解如何在同一项目中使用多个文件,并将它们链接在一起,同时理解和利用多态性。我们使用多个文件作为我们必须的简要状态。为我们提供了文件和定义。
以下内容应该在从起始位置到目标位置的地形图(0-3 的数字数组)上进行"广度优先"搜索。这是关于寻路的。
这是我到目前为止所拥有的:
#include "SearchBreadthfirst.h" // Declaration of this class
#include <iostream>
#include <list>
using namespace std;
bool CSearchBreadthFirst::FindPath(TerrainMap& terrain, unique_ptr<SNode> start, unique_ptr<SNode> goal, NodeList& path)
{
// Initialise Lists
NodeList closedList; // Closed list of nodes
NodeList openList; // Open list of nodes
unique_ptr<SNode>currentNode(new SNode); // Allows the current node to be stored
unique_ptr<SNode>nextNode(new SNode); // Allows the next nodes to be stored in the open list
// Boolean Variables
bool goalFound = false; // Returns true when the goal is found
// Start Search
openList.push_front(move(start)); // Push the start node onto the open list
// If there is data in the open list and the goal hasn't ben found
while (!openList.empty() || goalFound == false)
{
cout << endl << "Open list front:" << openList.front() << endl;
currentNode->x = openList.front()->x;
currentNode->y = openList.front()->y;
currentNode->score = openList.front()->score;
currentNode->parent = openList.front()->parent;
}
}
它突出了这句话:currentNode->x = openList.front()->x;
是问题所在。
NodeList
类型在SearchBreadthfirst.h
中定义如下:
using NodeList = deque<unique_ptr<SNode>>;
SNode
在SearchBreadthfirst.h
中也有这样的定义:
struct SNode
{
int x; // x coordinate
int y; // y coordinate
int score; // used in more complex algorithms
SNode* parent = 0; // note use of raw pointer here
};
程序在构建时中断。几天来我一直在尝试解决这个问题,所以任何帮助都非常感谢。如果我遗漏了什么,请告诉我,我会添加它!
詹姆斯
错误消息Attempting to reference a deleted function
是由于std::unique_ptr
显式delete
其复制构造函数,因为显然,它包含的指针只有一个副本。
当您致电时
openList.push_front(start);
您正在创建类型为unique_ptr<SNode>
的start
的副本,并且它有一个已删除的复制构造函数。为了将std::unique_ptr
与容器一起使用,您需要将对象移动到容器中。你需要做这样的事情:
openList.push_front(move(start));
这会将start
移动到deque
中,并将其中的内容移动到start
中。
- 区分接受常量参数的函数引用/指针和与函数参数同名的非常量参数
- 类 Referention 中C++回调函数引用非静态函数
- 使用函数引用指向节点的指针删除链表中的节点?
- 解释通过从函数引用返回数组的语法
- "Class1"类"Class2"对象作为私有数据成员。如何通过"Class 2"函数引用"Class1"对象?
- 使用默认构造函数引用成员变量初始化错误
- 无法调用函数引用 c++
- 使用 decltype(this) 获取函数引用
- 我应该如何定义返回指针的函数?(引用指针与指针指针)
- 从内联函数引用文件静态变量
- Boost::将sigaction函数引用绑定到实例
- 一种比函数引用更有效的方法
- 奇怪的未定义函数引用,函数调用C++不存在
- 是否可以检测绑定成员函数引用的对象是否被删除或销毁
- 构造函数引用参数导致seg错误
- 是否可以使函数模板从函数引用中获取“decltype”
- 无法让 Lua 函数引用"self"
- 如何解析变量和函数引用(Linker & Compiler)?
- 从不同模块调用函数 - 引用错误
- 如何在主函数中连接到数据库,然后从其他函数引用它