Affected files: .obsidian/workspace 02. PARA/03. Resources(資源)/C++17/rvalue.md
699 B
699 B
- 等號右邊的值
- 臨時的值,例如運算的結果
- 無法被取址(address-of)的物件
rvalue參考
可以用&&來參考rvalue。例如:
int c{5};
int&& rtepm {c + 3};
關於lvalue、rvalue的分別可以參考Value categories - cppreference.com,或是rvalue 參考等文章。這邊講用法跟好處。 rvalue reference可以減少無間的複製成本。例如:
std::string longStr = "qwertyuiopasdfghjklzxcbnm";
std::string anotherLong = longStr;
這時longStr會被複製一份anotherLong,把longStr換成很大的buffer,