Error: C2280 Creating a vector of unique_ptr to Class
Error: C2280 Creating a vector of unique_ptr to Class
似乎在 vector<unique_ptr<UserInterface>>
中使用 unique_ptr 时出现错误:
Error 1 error C2280: 'std::unique_ptr<UserInterface,std::default_delete<_Ty>>::unique_ptr(const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)' : attempting to reference a deleted function c:\pr...ude\xmemory0 593 1 Win32Project1
看起来,没有任何配置允许我存储指向 UserInterface class 的 [smart] 指针,它具有一个简单的结构:
#define InterfaceContruct vector<unique_ptr<UserInterface>>
class UserInterfaceMgmt
{
public:
UserInterfaceMgmt();
~UserInterfaceMgmt();
InterfaceContruct Interface;
void AddUIElement();
void RemoveUIElement();
void DrawInterface();
void MoveElement();
private:
};
即使没有调用函数,也会出现错误(InterfaceContruct Interface;
已实例化)我尝试将复制构造函数放入 private
但它仍然存在。
.cpp
文件是:
#include "stdafx.h"
#include "UserInterfaceMgmt.h"
UserInterfaceMgmt::UserInterfaceMgmt()
{
}
UserInterfaceMgmt::~UserInterfaceMgmt()
{
}
void UserInterfaceMgmt::DrawInterface(){
for (UINT i = 0; i < Interface.size(); i++)
{
Interface[i]->Draw();
}
}
std::vector
(以及 std::
中的大多数其他容器)要求值类型是可复制构造的。 std::unique_ptr
不可复制构造。使用 std::shared_ptr
或任何其他复制构造类型/指针。
线索是寻找attempting to reference a deleted function
。这意味着 = delete
已经使用了一些方法。例如:
struct Foo
{
Foo(const Foo & rhs) = delete; // A deleted function
}
似乎在 vector<unique_ptr<UserInterface>>
中使用 unique_ptr 时出现错误:
Error 1 error C2280: 'std::unique_ptr<UserInterface,std::default_delete<_Ty>>::unique_ptr(const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)' : attempting to reference a deleted function c:\pr...ude\xmemory0 593 1 Win32Project1
看起来,没有任何配置允许我存储指向 UserInterface class 的 [smart] 指针,它具有一个简单的结构:
#define InterfaceContruct vector<unique_ptr<UserInterface>>
class UserInterfaceMgmt
{
public:
UserInterfaceMgmt();
~UserInterfaceMgmt();
InterfaceContruct Interface;
void AddUIElement();
void RemoveUIElement();
void DrawInterface();
void MoveElement();
private:
};
即使没有调用函数,也会出现错误(InterfaceContruct Interface;
已实例化)我尝试将复制构造函数放入 private
但它仍然存在。
.cpp
文件是:
#include "stdafx.h"
#include "UserInterfaceMgmt.h"
UserInterfaceMgmt::UserInterfaceMgmt()
{
}
UserInterfaceMgmt::~UserInterfaceMgmt()
{
}
void UserInterfaceMgmt::DrawInterface(){
for (UINT i = 0; i < Interface.size(); i++)
{
Interface[i]->Draw();
}
}
std::vector
(以及 std::
中的大多数其他容器)要求值类型是可复制构造的。 std::unique_ptr
不可复制构造。使用 std::shared_ptr
或任何其他复制构造类型/指针。
线索是寻找attempting to reference a deleted function
。这意味着 = delete
已经使用了一些方法。例如:
struct Foo
{
Foo(const Foo & rhs) = delete; // A deleted function
}