Well, there is a good chance that you are using VS, since it doesn't automagically generate move member functions for you. (Otherwise ph_list.push_back(move(ph))
would work.)
The unique_ptr
does have move-assignment operator, which implies ownership transfer. To call move-assignment operator (or move constructor for that matter) you need to work with rvalue. (T&&
, where T
is not meant as template here, as that invokes something a bit different) To obtain a rvalue, you either have to work with a temporary (such as a return value from a function) or you have to manually cast lvalue to rvalue. This is done via std::move
(to signify intent) or a bit more wordy static_cast
.
To solve this, either use emplace_back
or declare proper constructors manually, and use either emplace_back
or push_back(move())
.
---edit---
Note: emplace_back
probably shouldn't require move-assignment constructor to work, but you will run into trouble when trying to extract the object from the list.