【发布时间】:2021-03-05 03:42:39
【问题描述】:
我有以下代码:
struct Foo
{
int type;
union
{
int intValue;
double doubleValue;
std::wstring stringValue;
} value;
};
然后在我的 cpp 文件中:
std::vector<Foo> row;
some_class_object->func( row );
我得到了:
error C2280: 'void *Foo::__delDtor(unsigned int)': attempting to reference a deleted function
这里有什么问题?
编辑:
所以我添加了这个析构函数:
~Foo()
{
if( type ==3 )
value.stringValue.~std::wstring();
}
我得到一个错误:
error C2061: syntax error: identifier 'wstring'.
在这种情况下,显然 std::string 与 std::wstring 很重要......
不知道。
EDIT2:
我现在得到:
error C2280: 'Foo::<unnamed-type-value>::~<unnamed-type-value>(void)': attempting to reference a deleted function
【问题讨论】:
-
使用
union只实现variant,然后使用它。 Boost 为 pre-C++17 提供了一个,std 从 C++17 开始提供。