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

Move constructor involving const unique_ptr

$
0
0

In the code below, I made p const because it will never point to any other int during Foo's lifetime. This doesn't compile, as the unique_ptr's copy constructor is called, which is obviously deleted. Are there any solutions besides making p non-const? Thanks.

#include <memory>using namespace std;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>