列出所有的情况下,当一个数组不转换为一个指向一个单一的元素? [英] List all the situations when an array is not converted to a pointer to a single element?

查看:130
本文介绍了列出所有的情况下,当一个数组不转换为一个指向一个单一的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我还遇到3的情况下保持数组作为数组:
(假设 INT ARR [3] [4];

So far I have encountered 3 situations where array stays as an array: (assume int arr[3][4];)


  1. 的sizeof(ARR)给出了总规模(而不是一个元素)

  2. &放大器;常用3 + 1:按总规模推进的地址

  3. 在范围内结合内部数组的引用为:

//

   for(const auto &row : arr)
       for(auto col : row)
           cout << col << endl;

问题:
这是否用尽所有的地方阵列将不转换为一个指向一个元素的情况呢?
如果没有,是否有决定它的系统方法?

Question: Does this exhaust all the situations where array is not converted to a pointer to a single element? If not, is there a systematic way of deciding it?

推荐答案

大多数此转换偏偏被覆盖的情况下,[EXPR]#8:

Most of the cases where this conversion happens are covered by [expr]#8:

每当glvalue前pression显示为操作员的操作数期望一个prvalue为操作数,左值到右值(4.1),阵列到指针(4.2),或函数于─指针(4.3)标准转换应用到前pression转换为prvalue

Whenever a glvalue expression appears as an operand of an operator that expects a prvalue for that operand, the lvalue-to-rvalue (4.1), array-to-pointer (4.2), or function-to-pointer (4.3) standard conversions are applied to convert the expression to a prvalue.

所有的经营者可采取改编期望prvalue(或以其他方式明确要求这种转换),除了

All of the operators which can take arr expect a prvalue (or otherwise explicitly request this conversion), except for:


  • 单目&安培;

  • 的sizeof

  • ++

  • -

  • alignof

  • 的typeid

  • unary &
  • sizeof
  • ++
  • --
  • alignof
  • typeid

(注:此列表可能不够详尽,如果有人指出,其他的情况下,我将更新它)

(Note: this list might not be exhaustive, I will update it if someone points out other cases!)

现在,有各种可能的情况下,我们可以使用改编,这是没有任何运营商的操作数。其中一些案件执行转换,有些则没有。那些执行转换的是:

Now, There are various possible cases where we can use arr and it is not the operand of any operator. Some of those cases perform the conversion and some don't. The ones that do perform the conversion are:


  • 使用改编作为函数参数,但不匹配的原型参数

  • 模板类型扣除某些情况下

  • 演绎的返回类型的拉姆达

  • using arr as a function argument but not matching a prototype parameter
  • some cases of template type deduction
  • deducing the return type of a lambda

值得注意的是,转换是不受绑定改编来参照执行(这是在基于范围for循环会发生什么)。这是通过[dcl.init.ref]#5覆盖。在行 T&安培; REF =改编; = 不是赋值运算符;它的语法声明的一部分。

Notably, the conversion is not performed by binding arr to a reference (this is what happens in the range-based for-loop). This is covered by [dcl.init.ref]#5. In the line T &ref = arr;, the = is not the assignment operator; it's part of the syntax for declarations.

这篇关于列出所有的情况下,当一个数组不转换为一个指向一个单一的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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