我正在使用Visual Studio 2013,我遇到了一个奇怪的问题.当我导出一个类时,它会抛出"试图引用已删除的函数"错误.但是,当未导出类时,它的行为正确.
让我举个例子...
class Foo
{
};
// note the export
class __declspec(dllexport) Bar
{
// the following line throws the error
std::unordered_map<std::string, std::unique_ptr<Foo>> map;
};
Run Code Online (Sandbox Code Playgroud)
现在,如果我删除导出,所以它看起来像以下一样按预期工作.
class Foo
{
};
// note I removed the export
class Bar
{
// the following line now compiles without any issues
std::unordered_map<std::string, std::unique_ptr<Foo>> map;
};
Run Code Online (Sandbox Code Playgroud)
现在,这是一个编译器错误还是我显然缺少的其他东西?仅供参考,上述代码适用于GCC或Clang.
Error 2 error C2280: 'std::unique_ptr<Foo,std::default_delete<_Ty>>::unique_ptr(const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)' : attempting to reference a deleted function c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0 592
Run Code Online (Sandbox Code Playgroud)