Quantcast
Channel: Move constructor involving const unique_ptr - Stack Overflow
Viewing all articles
Browse latest Browse all 6

Answer by user557583 for Move constructor involving const unique_ptr

$
0
0

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;};

Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>