如何在一个语句中定义对数组的引用

use*_*779 1 c++

我定义了一个中间typedef,以定义对固定大小数组的引用.

typedef int CI[0x10];
CI& arr=*(CI*)mypointer;
Run Code Online (Sandbox Code Playgroud)

写它就像以后允许我使用它 countof(arr)

我试着在一个声明中写下它,而下面是我失败的尝试.我知道这是错的,因为"&"应该在"int"和"[0x10]"中,而不是在arr1上,但可以在一个语句中写入它;

int (arr1&)[classInfoN]=*(CI*)mypointer;
Run Code Online (Sandbox Code Playgroud)

Ben*_*igt 8

你有&错误的地方.它总是位于标识符的左侧,就像您的工作示例一样.

所以:

int (&arr1)[0x10] = *reinterpret_cast<int (*)[0x10]>(mypointer);
Run Code Online (Sandbox Code Playgroud)