次のコードは、unique_ptrのコピーコンストラクタが何らかの形で呼び出されたと不平を言ってコンパイラエラーが発生してgcc 5.3でコンパイルできません。誰かがなぜこれが起こるのか説明できますか?unique_ptrの両端ベクトルのコンパイラエラー
#include <iostream>
#include <memory>
#include <deque>
using Foo = std::deque<std::unique_ptr<int>>;
void foo() {
std::vector<Foo> a;
a.emplace_back(); // this fails to compile
}
コンパイラエラーの重要な行は、次のとおりです。
gcc-4.9.2/include/c++/4.9.2/bits/stl_construct.h:75:7: 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>]’ { ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); }
ああ、これは混乱です。 –
うわー、素敵............ –
あなたは ''と ''を含めるべきですが、それは ''ではありません。それはここで重要ではない。 –