dimanche 15 mars 2015

Can't push_back move(NonCopyable) to vector


I have a NonCopyable class (due to its unique_ptr field). I want to create a vector of NonCopyable elements but the following code wouldn't compile



NonCopyable nc;
vector<NonCopyable> vec;
vec.push_back(move(nc));


The error message is Call to implicitly-deleted copy constructor of NonCopyable. Why doesn't the move optimization work in this case? How to fix it elegantly (without defining a copy constructor for NonCopyable)?


I'm using clang 6.0.




Aucun commentaire:

Enregistrer un commentaire