我的短代码如下:
#include <memory>
#include <vector>
#include <tuple>
using namespace std;
struct A
{
A() {}
vector<unique_ptr<int>> m;
// Change the above line to "unique_ptr<int> m;" removes the compilation error
// Or add a line "A(A const&) = delete;" removes the compilation error also
};
struct B
{
tuple<A> t;
};
int main()
{
A a;
B b;
return 0;
}
VC2013 NOV CTP编译报错:
error C2280: 'std::unique_ptr<int,std::default_delete<_Ty>>::unique_ptr(const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)' : attempting to reference a deleted function xmemory0 593
这是编译器错误还是代码错误?
最佳答案
这是 Visual Studio 中的一个错误;根据@Gonmator 的评论,它已从 VS2013 更新 1 开始修复。
它可能类似于报告的错误,例如
https://connect.microsoft.com/VisualStudio/feedback/details/801826/std-tuple-with-rvalue-references-not-working-if-clr-enabled
或者
https://connect.microsoft.com/VisualStudio/feedback/details/891428/c-std-pair-has-no-default-move-constructor
— 显然 MSVC 有几个涉及“移动语义 + std::tuple”的残留错误。
关于c++ - vector<unique_ptr> 带来麻烦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22951295/