RValues的什么构成? [英] What constitutes of RValues?

查看:306
本文介绍了RValues的什么构成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 常量是否构成RValues? const int x = 0; 至少可以操作一次。

  2. 现在,编译器创建的临时对象也是RValues当它们具有可操纵的存储器区域时。为什么会这样?

    因为他们不能被用户修改?这是原因吗?

因此,用户不能操作的内存区域称为RValue?

解决方案



  1. 常量构成RValues? const int x = 0;

在您的声明中,<$ c $可以操作
至少一次。 c> x 既不是右值,也不是左值,则称为 declarator-id 。 (参见C ++ 03中的语法8/4)当在(子)表达式中使用它时,它是一个不可修改的左值,可以初始化为任何常量表达式


2.现在,编译器创建的临时对象也是RValues,即使它们有可操作的内存区域。为什么会这样呢?
因为他们不能被用户修改?这是原因吗?


类类型的Rvalue可以是可修改的或不可修改的,但是内置类型的右值总是cv-unqualified。


§3.10 / 9类右值可以有cv限定类型;考虑这个例子:




<

  struct S {
int x;
void f(int s){x = s; }
};

//形式:无法分配到内置类型的右值。
S()。x = 42;

//有效:成员函数可用于修改rvalue的指示。
S()。f(42);

子表达式 S()类类型的右值,其生存期是结束; 全表达式


RValues are things which are not maniputable regions of memory, so literals like integers are considered RValues.

  1. Do constants constitute RValues? const int x = 0; is maniputable at least one time.
  2. Now, the temporary objects created by the compiler are also RValues even when they have maniputable memory regions. Why is that so?
    Because they cannot be modified by "users"? Is this the reason?

So, a memory region which is NOT maniputable by the "users" is called RValue?

解决方案

  1. Do constants constitute RValues? const int x = 0; is maniputable at least one time.

In your declaration, x is neither an rvalue or lvalue, it is called a declarator-id. (See grammar of 8/4 in C++03) When it is used in a (sub-)expression it is a non-modifiable lvalue which can be initialized to any constant expression.

2.Now, the temporary objects created by the compiler are also RValues even when they have maniputable memory regions. Why is that so? Because they cannot be modified by "users"? Is this the reason?

Rvalue of a class type can either be modifiable or non-modifiable but rvalues of built-in types are always cv-unqualified.

§ 3.10/9 Class rvalues can have cv-qualified types; non-class rvalues always have cv-unqualified types.

Consider this example:

struct S {
     int x;
     void f(int s) { x = s; }
};

// ill-formed: Cannot assign to an rvalue of built-in type.
S().x = 42;

// Valid: A member function can be used to modify the referent of rvalue.
S().f(42);

The sub-expression S() creates an rvalue of class type whose lifetime is the end of ; full-expression.

这篇关于RValues的什么构成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆