vector<unique_ptr<int>>に、push_backしたいのですができません。
以下のコードで、intsにiをpush_backしたいです。
c++
1#include<memory> 2#include<vector> 3 4int main() 5{ 6 std::vector<std::unique_ptr<int>> ints; 7 8 std::unique_ptr<int> i; 9 i.reset(new int); 10 11 // コンパイルエラーになってしまう 12 ints.push_back(i); 13 14 return 0; 15}
以下は、コンパイルエラーの抜粋です。(全くわかりません・・・)
c++
1/usr/include/c++/7/ext/new_allocator.h:136:4: error: 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 { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
どうしたらいいのでしょうか・・・。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/13 03:38
2019/04/13 04:13
2019/04/13 04:26