使用整数指针将左值转换为右值
Lvalue to rvalue conversion with integer pointer
如果我正确读取隐式转换:
左值到右值的转换
任何非函数、非数组类型 T 的 glvalue 都可以隐式转换为相同类型的 prvalue。[..]
除非在未计算的上下文中遇到(在 sizeof、typeid、noexexcept 或 decltype 的操作数中(,否则此转换使用原始 glvalue 作为构造函数参数有效地复制构造类型 T 的临时对象,并且该临时对象作为 prvalue 返回。
那为什么这不起作用呢?
int* iptr = nullptr;
int*&& irr = iptr; // Cannot bind lvalue to rvalue reference
类型 int*
应该通过临时隐式转换为相同类型的 prvalue,从而绑定到右值引用而不会出现问题。
标准明确指出这是格式不正确的; 不会(不应该(考虑左值到右值的转换。
来自 [dcl.init.ref]/5.4.4:
如果引用是右值引用,则初始值设定项表达式不应是左值。
[ 示例:
double d2 = 1.0; double&& rrd2 = d2; // error: initializer is lvalue of related type
相关文章:
- 努力将整数转换为链表。不知道我在这里做错了什么
- 将"打开的CV图像"中的"颜色"转换为整数格式
- 如何在C++中将整数转换为其数字数组
- 尝试将字符串/字符转换为整数会产生意外结果
- 如何使用C++将字符串中的字符转换为整数变量
- 如何将整数字符串转换为整数的二维向量?
- 如果整数与指针大小相同,则重新解释将整数转换为指针双射是否具有双射作用?
- 使用 "stringstream " 将字符串转换为整数
- 将字符串转换为浮点数或整数,而无需使用内置函数(如 atoi 或 atof)
- 如何检测 std::vector::emplace_back 上的隐式转换损失整数精度
- 如何防止双精度值到整数的隐式转换
- 为什么此指针值不能转换为整数的规则是什么?
- 如何解决隐式转换丢失整数精度:'size_t'(又名"无符号长")到'int'警告?
- 在 C++ 中将整数数组转换为位集表示形式的最佳方法?
- 为什么在将 void 指针转换为整数指针时出现分段错误
- 将字符串(可以是十进制字符串或十六进制字符串)转换为整数C++
- 整数类型应该显式转换(例如"int"到"无符号")还是只会增加混乱?
- 如何使用 STL 算法将整数向量转换为字符串向量?
- 无法将"整数 (*)[m]"转换为"整数 (*)[100000]
- 静态强制转换允许转换对象指针,但不允许转换整数