我想我可能已经想出了数组类型的右值的例子 [英] I think I may have come up with an example of rvalue of array type

查看:141
本文介绍了我想我可能已经想出了数组类型的右值的例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++ 4.2节03 N°1:结果
左值或类型的右值数组的NT或结合的T未知的阵列可以被转换成类型的指针T.右值的结果是一个指针数组的第一个元素。

什么已经在此声明被迷惑了很长的时间,我是,我不明白是什么数组类型的右值意味着什么。这就是说,我不能拿出一个前pression其类型是一个数组,其结果是右值。我读线程,基本上问同样的问题,接受的答案是没有,没有数组类型的右值。我想我只是可能有矛盾这一点。

What has been confusing in this statement for a long time for me was that I didn't quite understand what an rvalue of array type would mean. That is, I couldn't come up with an expression whose type were an array and the result were an rvalue. I read this thread, which basically asks the same question and the accepted answer is "no, there is no rvalue of array type". I think I just might have a contradiction to this.

C ++ 03§5.2.5N°4:(约前pression E1.E2)结果
<青霉>如果E 2是一个非静态数据成员,和E1的类型是CQ1 VQ1 X,和E2的类型是CQ2 VQ2 T,前pression指定对象的命名构件由第一八佰伴pression指定。如果E1是一个左值,然后E1.E2是一个左值。的

我认为不然就是右值(E2提供的是不是一个参考,这种情况下,由覆盖§5.2.5N°3 ),因此...

I assume that otherwise it is an rvalue (provided E2 is not a reference, that case is covered by §5.2.5 N°3) and therefore...

struct A
{
   int a[4];
};
A f()
{
   A a;
   return a; 
}
int main()
{
   f().a; //I think this is an rvalue of array type...
}

我在这里看到两个选项:结果
选项1:我是正确的,华友世纪,耶,爽。在这种情况下,问题是:有没有其他的例子结果?
选项2:我不正确,在此情况下的问题是:这是标准的缺陷

I see two options here:
Option1: I am correct, hurray, yay, cool. In this case the question is: are there other examples?
Option2: I am incorrect, in this case the question is: is this a defect of the standard?

我不知道1,但我真的怀疑2,因为当他们谈论的功能到指针的转换,他们只是提到函数类型的左值(AP明显preciating,有没有这样的右值) 。所以这是非常有可能,他们还以为华南简介数组类型的右值。

I don't know about 1, but I really doubt about 2 because when they speak about function-to-pointer conversions they mention just lvalues of function types (obviously appreciating that there are no rvalues of such). So it's very likely they had thought abour rvalues of array types.

所以,基本上我的问题是我是否没有拿出数组类型的右值的一个例子,如果没有,请提供一个有效的,我相信stongly存在。

So, basically my question is whether or not I have come up with an example of rvalue of array type, and if not, please provide a valid one, which I stongly believe there exists.

推荐答案

是的,你是正确的。这位前pression是数组类型的右值。这不是一个缺陷 - 委员会知道它,它也是在C89,一个常见的​​问题,只允许转换为数组类型的左值指针。因此,你不能索引或取消引用像一个数组F()。在。 C99固定这一点,C ++没有问题的。

Yes, you are correct. The expression is an rvalue of array type. This is not a defect - the committee knows about it, and it was also a common issue in C89, which only allows conversion to pointers for lvalues of array types. As a consequence, you could not index or dereference an array like f().a. C99 fixed this, and C++ does not have a problem with it.

注意,无论它是否是一个rvalue是独立于前pression是否表示一个对象。 C ++ 03无意中省略说右值前pression是数组类型的表示对象。这是固定的C ++ 0x 由DR#450

Note that whether or not it is an rvalue is independent to whether or not the expression denotes an object. C++03 accidentally omitted to say that an rvalue expression that is of array type denotes an object. This was fixed in C++0x by DR#450.

(显然AP preciating,有没有这样的右值)

(obviously appreciating that there are no rvalues of such)

有实际功能类型的右值。这些发生由一类成员访问前pression表示非静态成员函数

There are actually rvalues of function types. These occur for non-static member functions denoted by a class member access expression

struct A { void f(); };

/* A().f is an rvalue of type "void()" */
int main() { A().f(); }

这篇关于我想我可能已经想出了数组类型的右值的例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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