【发布时间】:2014-07-06 19:14:37
【问题描述】:
我正在使用 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;
};
现在,如果我删除导出,那么它看起来像下面的一切都按预期工作。
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;
};
现在,这是编译器错误还是我明显遗漏的其他东西?仅供参考,以上代码适用于 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
【问题讨论】:
-
这似乎不是完整的错误消息。请编辑您的问题以包含 complete 和 unedited 错误日志。
-
我现在已经粘贴了完整的错误。
标签: c++ visual-c++ c++11