2014-04-09 73 views
0

我有短碼如下面矢量<unique_ptr>給出麻煩

#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編譯器爲錯誤:

錯誤1個錯誤C2280:「的std ::的unique_ptr> ::的unique_ptr(常量的std ::的unique_ptr < _Ty,性病:: default_delete < _Ty >> &)」:試圖引用刪除的功能xmemory0 593

這是一個編譯器錯誤或代碼錯誤?

+1

[在此使用g ++](http://coliru.stacked-crooked.com/a/4427e08c08e83a19) –

+0

因此,這是一個編譯器錯誤。謝謝。 – user1899020

+0

爲什麼要刪除複製構造函數?如果你不想讓它被使用,你能不能把它變成「私人」?而這個錯誤是因爲你正在做的事情是觸發複製構造函數。在C++中,我還沒有足夠的經文來告訴你這是什麼。 – Dan

回答

1

這是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」。