#cpp ```mermaid flowchart TD expression --> glvalue expression --> rvalue glvalue --> lvalue glvalue --> xvalue rvalue --> xvalue rvalue --> prvalue ``` - **lvalue**:开发人员可以拿到地址 / name 来访问的表达式 - **prvalue**:pure rvalue,表达式没有可供开发人员访问的地址,如 - literals(string literal 是 lvalue 是个例外) - 返回非引用类型的函数调用 - 表达式求值后创建的临时对象,只有编译器能访问 - 1+1 - **xvalue**:expiring value,有可供访问的地址,但是后续不在使用,可以重用。 - 如返回右值引用的函数调用( std::move) - **glvalue**:generalized value,有访问地址 - C 语言中概念: - 出现在赋值运算左边的为 lvalue,右边的为 rvalue - `lvalue = rvalue` - lvalue 可以放在右边作为 rvalue 使用。 - C++的例外:const lvalue 无法出现在左边。 - 参考资料 - [cpprefernce](https://en.cppreference.com/w/cpp/language/value_category) - [microsoft learn](https://learn.microsoft.com/en-us/cpp/cpp/lvalues-and-rvalues-visual-cpp?view=msvc-170) - [Back to Basics: Understanding Value Categories - Ben Saks - CppCon 2019](https://www.youtube.com/watch?v=XS2JddPq7GQ)