Quantcast
Channel: Move constructor involving const unique_ptr - Stack Overflow
Browsing latest articles
Browse All 6 View Live

Answer by user557583 for Move constructor involving const unique_ptr

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...

View Article



Answer by prisco.napoli for Move constructor involving const unique_ptr

To understand why your code does not compile, reflect how you have declared Foo class and how move semantics is generally implemented.Declaring a const unique_ptr<T> p, you mean that p itself...

View Article

Answer by Persixty for Move constructor involving const unique_ptr

The semantics of your move constructor are contradictory.You have declared a const std::unique_ptr which will (uniquely) own the value it is initialised with.But you've declared a move constructor that...

View Article

Answer by szulak for Move constructor involving const unique_ptr

Concept of using std::unique_ptr is representing a sole ownership of an object. What you're trying to achieve is having a Foo class own an object (which is expressed by std::unique_ptr) and making it...

View Article

Answer by user3920237 for Move constructor involving const unique_ptr

If you want to prevent transfer of ownership, you can use a const std::unique_ptr<T>. This is not very useful.If you want to prevent modifying the object it holds, you can use a...

View Article


Move constructor involving const unique_ptr

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....

View Article
Browsing latest articles
Browse All 6 View Live




Latest Images