在學習c++的線程標准庫的時候同時碰到了右值引用(&&)和c++11的move構造函數,

簡單的看了幾篇博客,大概了解了左值、左值引用、右值、右值引用以及在左值明確放棄對其資源的所有權,通過std::move()來將其轉為右值引用這五點內容:
以下鏈接都很簡短,看兩遍我相信就能有比較好的理解了:
一個std::move()的例程(參考:c++11 std::move() 的使用)
#include <iostream> #include <utility> #include <vector> #include <string>
int main() { std::string str = "Hello"; std::vector<std::string> v; //調用常規的拷貝構造函數,新建字符數組,拷貝數據
v.push_back(str); std::cout << "After copy, str is \"" << str << "\"\n"; //調用移動構造函數,掏空str,掏空后,最好不要使用str
v.push_back(std::move(str)); std::cout << "After move, str is \"" << str << "\"\n"; std::cout << "The contents of the vector are \"" << v[0] << "\", \"" << v[1] << "\"\n"; }

可以看到,std::move()就是將左值轉換為對應的右值引用類型,且調用后銷毀
