+ 1
std::move visual studio warning?
A colleague of mine said that using move in Visual Studio gave a warning like “use of a moved from object: …”. Can someone please run the MWE in visual studio below and confirm if this happens? If the warning does come up, any suggestions? https://code.sololearn.com/cPHA2z6JXvID/?ref=app
1 Antwort
+ 4
While I can't test the code in Visual Studio, the warning would be valid since you're using 'y' which had been moved into 'z'. While this has no conquences on std::string, some other class might have a move constructor that leaves the moved-from object unusable if you're not aware of what operations are valid on them. A simple example would be moving a unique_ptr and using it without realising that a move-from unique_ptr stores a null pointer.
Related thread on SO
https://stackoverflow.com/questions/7027523/what-can-i-do-with-a-moved-from-object