我的类中几乎所有的构造函数和解构函数都被隐式定义为已删除?
Almost all of the constructors and deconstructors in my classes are implicitly defined as deleted?
Variable.h
#pragma once
#include <unordered_map>
namespace ssu
{
class GenericArray;
class Variable
{
enum Type
{
NONE,
BOOL,
STRING,
INT,
FLOAT,
ARRAY,
DICT,
TYPE_MAX
};
private:
template<typename Key, typename Value>
using Dictionary = std::unordered_map<Key, Value>;
union
{
bool _bool;
std::string _string;
int64_t _int;
double _float;
GenericArray _array;
Dictionary<std::string, Variable&> _dict;
};
Type m_Type;
private:
static inline Variable eval();
public:
Variable(const bool p_bool);
Variable(const std::string p_string);
Variable(const int64_t p_int);
Variable(const double p_float);
Variable(const GenericArray p_array);
Variable(const Dictionary<std::string, Variable&> p_dict);
};
class GenericArray
{
private:
struct Block
{
Variable m_Data;
Block* m_Next;
Block* m_Prev;
};
Block* m_First;
Block* m_Last;
size_t m_Size = 0;
public:
void push_back(Variable p_var);
void erase(int index);
void erase(int first, int end);
Variable& operator[] (int index);
};
}
可变.cpp
#include "variable.h"
namespace ssu
{
void GenericArray::push_back(Variable p_var)
{
Block* block = new Block;
block->m_Data = p_var;
if (!m_First || !m_Last)
{
m_First = block;
m_Last = block;
}
}
}
我对我遇到的错误感到非常困惑。我尝试编译代码,但它不会构建。这在以前从未发生过。
如果很重要,Variable
类旨在用作联合中所有值的泛型类型。也许GenericArray
和Variable
之间的递归导致了这个问题?
这些是我遇到的错误类型:
File Severity Code Line Description
variable.cpp Error C2280 6 'ssu::Variable::~Variable(void)': attempting to reference a deleted function
variable.cpp Error E1790 7 the default constructor of "ssu::GenericArray::Block" cannot be referenced -- it is a deleted function
variable.cpp Error E1776 8 function "ssu::Variable::operator=(const ssu::Variable &)" (declared implicitly) cannot be referenced -- it is a deleted function
variable.h Error C2079 36 'ssu::Variable::_array' uses undefined class 'ssu::GenericArray'
variable.h Warning C4624 50 'ssu::Variable': destructor was implicitly defined as deleted
variable.h Warning C4624 60 'ssu::GenericArray::Block': destructor was implicitly defined as deleted
variable.h Error C2079 36 'ssu::Variable::_array' uses undefined class 'ssu::GenericArray'
variable.h Warning C4624 50 'ssu::Variable': destructor was implicitly defined as deleted
variable.h Warning C4624 60 'ssu::GenericArray::Block': destructor was implicitly defined as deleted
variable.cpp Error C2280 7 'ssu::GenericArray::Block::Block(void)': attempting to reference a deleted function
variable.cpp Error C2280 8 'ssu::Variable &ssu::Variable::operator =(const ssu::Variable &)': attempting to reference a deleted function
联合声明
联合不能包含具有非平凡特殊成员函数(复制构造函数、复制赋值运算符或析构函数(的非静态数据成员。
如果联合包含具有非平凡特殊成员函数(复制/移动构造函数、复制/移动赋值或析构函数(的非静态数据成员,则该函数在联合中默认删除,并且需要由程序员显式定义。
如果联合包含具有非平凡默认构造函数的非静态数据成员,则默认情况下将删除联合的默认构造函数,除非联合的变体成员具有默认成员初始值设定项。
具有非平凡默认构造函数的非静态数据成员是 std::string 和 Dictionary。
如果类数据成员具有已删除的构造函数,则默认情况下将删除类默认构造函数。
相关文章:
- 共享指针和具有自定义删除程序的唯一指针之间的语法差异背后的任何原因
- 如何使用 C 指针的自定义删除器创建unique_ptr?
- 在地图中使用自定义删除器存储unique_ptr
- 指向重载静态成员的函数指针 - 在unique_ptr中用作自定义删除器
- 在unique_ptr<>中使用自定义删除程序 (curl_formfree())
- C++自定义删除运算符不能正常工作?
- 如何在我的类unique_ptr中提供自定义删除器?
- 无法使用带有 std::move 的自定义删除器插入 std::unique_ptr
- 未调用 std::unique_ptr 中的自定义删除器
- 如何为unique_ptr管理的数组编写自定义删除器?
- 适用于 std::unique_ptr 的内存高效自定义删除器?
- 用于unique_ptr的有状态自定义删除程序
- shared_ptr<>到数组自定义删除器(带make_shared)
- 为什么使用自定义删除器unique_ptr不适用于 nullptr,而shared_ptr则适用于 nullptr?
- 如何在自定义删除器的情况下复制unique_ptr
- 自定义删除器,用于shared_ptr<>给出"无上下文错误"
- 智能指针自定义删除器中的处理条件
- 为什么unique_ptr不能阻止自定义删除程序的切片?
- 提升共享指针自定义删除器示例
- 在shared_ptr的自定义删除器中检查 nullptr 是否有意义?