It is because unique_ptr
has only the move-constructor, which means the initialization argument to p
cannot be const, while p
is const. I think what you wanted was to declare
unique_ptr p;
instead of
const unique_ptr p;
class Foo { public: // x is a large struct in reality Foo(const int* const x) : p(x) {}; Foo(Foo&& foo) : p(std::move(foo.p)) {}; private: const unique_ptr<int> p;};