以下のコードでfor文のところで、コンパイルエラーが出ます。
c++
1 #include<memory> 2 #include<vector> 3 #include<iostream> 4 5 int main() 6 { 7 std::vector<std::unique_ptr<int>> ints; 8 9 std::unique_ptr<int> i; 10 i.reset(new int); 11 12 ints.push_back(std::move(i)); 13 14 for(auto s : ints){ // コンパイルエラー 15 std::cout << "test" << std::endl; 16 } 17 18 return 0; 19 }
エラーの内容は以下です。
c++
1error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = int; _Dp = std::default_delete<int>]’ 2 for(auto is : ints){
全くわかりません、どうしたらいいのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/13 03:54
2019/04/13 05:07