文章目录

  • 参考
  • 左值
  • 右值
  • 临时值
  • glvalue
  • 纯右值
  • 总结

参考

https://en.cppreference.com/w/cpp/language/value_category

左值

历史习惯问题,叫左值,可以放在等号左边的对象和函数。例如,如果E是一个指针类型的表达式,*E就是一个左值表达式,可以指向E指向的对象或函数。另一个例子就是如果函数调用的返回值是一个左值引用,也是一个左值。
— An lvalue (so called, historically, because lvalues could appear on the left-hand side of an assignment expression) designates a function or an object. [ Example: If E is an expression of pointer type, then *E is an lvalue expression referring to the object or function to which E points. As another example, the result of calling a function whose return type is an lvalue reference is an lvalue. —end example ]

右值

prvalue和xvalue,都属于右值。有些名词的定义,没有办法说出来,只能通过举例来说明概念,这个右值就属于这一类。
右值的属性:右值不能使用取址符来取址。举例:
An rvalue can’t be used as the left-hand operand of the built-in assignment or compound assignment operators.
An rvalue may be used to initialize a const lvalue reference, in which case the lifetime of the object identified by the rvalue is extended until the scope of the reference ends.
An rvalue may be used to initialize an rvalue reference, in which case the lifetime of the object identified by the rvalue is extended until the scope of the reference ends.
When used as a function argument and when two overloads of the function are available, one taking rvalue reference parameter and the other taking lvalue reference to const parameter, an rvalue binds to the rvalue reference overload (thus, if both copy and move constructors are available, an rvalue argument invokes the move constructor, and likewise with copy and move assignment operators).

临时值

xvalue,也是是指向一个对象,但是通常快要终结的对象。xvalue是特定表达式牵扯rvalue引用的结果。
— An xvalue (an “eXpiring” value) also refers to an object, usually near the end of its lifetime (so that its resources may be moved, for example). An xvalue is the result of certain kinds of expressions involving rvalue references (8.3.2). [ Example: The result of calling a function whose return type is an rvalue reference is an xvalue. —end example ]

glvalue

glvalue是一般化的lvalue,是一个lvalue或者xvalue。
— A glvalue (“generalized” lvalue) is an lvalue or an xvalue.
rvalue,也是历史习惯的称号,rvalue可以出现在赋值符号的右边。rvalue是一个xvalue,临时对象或者是一个只,不关联任何对象。
— An rvalue (so called, historically, because rvalues could appear on the right-hand side of an assignment expression) is an xvalue, a temporary object (12.2) or subobject thereof, or a value that is not associated with an object.

纯右值

prvalue,纯右值;就是不是xvalue的rvalue。例子:就是如果一个函数调用返回了一个非引用的对象,就是纯右值。
— A prvalue (“pure” rvalue) is an rvalue that is not an xvalue. [ Example: The result of calling a function whose return type is not a reference is a prvalue. The value of a literal such as 12, 7.3e5, or true is also a prvalue. —end example ]

总结

每一个表达式只能属于其中的一种:lvalue,xvalue或者rvalue。

c++: rvalue, prvalue, lvalue, glvalue相关推荐

  1. C++中rvalue和lvalue详悉

    以下内容是参考书籍以及晚上的内容,整理而成,仅供参考~~ lvalue和rvalue 在计算机的远古时代,变量的lvalue和rvalue是指: lvalue:变量在内存中的位置.通过它能够找到内存中 ...

  2. C++的左值(lvalue)和右值(rvalue)

    背景 lvalue(左值).rvalue(右值)这些术语来自C语言(当然,C语言的术语习惯也可能来自更早的语言,Gemfield就不追溯了).在C语言中,lvalue和rvalue中的l和r是left ...

  3. 理解C++ lvalue与rvalue

    一个众所周知的危险错误是,函数返回了一个局部变量的指针或引用.一旦函数栈被销毁,这个指针就成为了野指针,导致未定义行为.而左值(lvalue)和右值(rvalue)的概念,本质上,是理解"程 ...

  4. c语言中字符串关于左值,关于左值lvalue和右值rvalue的一点理解

    发现很多朋友对"lvalue"和"rvalue"理解有误,我先谈谈自己对此的一些理解,并期望能够引起更多朋友的广泛讨论.也算起到抛砖引玉的作用吧.引用:注:这里 ...

  5. 理解lvalue和rvalue

    理解lvalue和rvalue Lvalues and Rvalues An object is a region of storage that can be examined and stored ...

  6. C++11中rvalue references的使用

    Rvalue references are a feature of C++ that was added with the C++11 standard. The syntax of an rval ...

  7. C++17之省略不必要的拷贝Copy Elision

    从C++发展历史看来,c++ 17引入了一个规则,要求在满足一定的条件下避免对象的复制,这在以前是可选的.C++17中一个叫做强制复制省略的技术就是基于这个观点的. 至少包括以下两项内容: 1. 返回 ...

  8. C/C++常见面试知识点总结附面试真题----20220326更新

    第一部分:计算机基础 1. C/C++内存有哪几种类型? C中,内存分为5个区:堆(malloc).栈(如局部变量.函数参数).程序代码区(存放二进制代码).全局/静态存储区(全局变量.static变 ...

  9. C++的std::move及相关概念

    1 相关概念 定义 ,需要理解三个方面的概念才有可能完全掌握. std::move : https://en.cppreference.com/w/cpp/utility/move static ca ...

最新文章

  1. [BTS]BizTalk学习之Functoid篇(ID Cross-References)
  2. python打印浮点数_python – 打印整数或带有n位小数的浮点数
  3. 功率谱 魏凤英统计程序_频谱、能量谱、功率谱、功率谱估计
  4. Linux Shell脚本Ldd命令原理及使用方法
  5. 解密迈向量产的百度Apollo自动驾驶技术与产品
  6. 【渝粤题库】陕西师范大学200411 数学建模 作业(专升本)
  7. java 代码重用需要注意的事项_程序员笔记|编写高性能的Java代码需要注意的4个问题...
  8. binder,hwbinder,vndbinder之间的关系
  9. 年轻人原地过年,也不忘搞钱
  10. iPhone 11全球热销:价格真香是硬道理
  11. 通过java程序实现mysql 批量一个表的子段更新另一个表的字段
  12. IDL | 实验一、IDL编码与运行
  13. 配置linux的jdk报错error while loading shared libraries: libjli.so
  14. Vision Transformer(VIT)代码分析——保姆级教程
  15. 预测大盘最准确的指标_迄今最权威的大盘预测K线指标下载
  16. 电脑桌面无图标,任务栏也不见了
  17. msdn i tell you网址及下载系统详细步骤
  18. 安卓机 input file图片上传无反应解决方案
  19. 了解以下几点,让你的精灵4RTK应用更专业
  20. 智云通CRM:做销售需要保持沟通的不紧迫感?

热门文章

  1. Java SE 7存档下载(官网包含所有1.7版本)
  2. 安装ubuntu系统详细步骤(双系统)
  3. 使用 React.js 开发 Chrome 插件
  4. PDF怎么快速转换成PPT格式?一分钟教你搞定
  5. 行业深度报告--短期业绩压力加速价值壁垒
  6. 图模型-随机游走算法
  7. UTC、TimeZone、TimeStamp
  8. 越权、cookie与session、认证和授权
  9. 聚观早报 | 皮克斯十年来首次大规模裁员;OpenAI网站访问量大增
  10. 文件服务器异常 选择签名,OSS上传文件后,服务器签名验证失败