我知道像这样的声明
int* a[5];
声明 a
作为指向 int
的 5 个指针的数组.但是我如何仅通过使用 C++ 标准来推断出这一点?
最佳答案
看看C++的语法就知道了。
ptr-declarator:
noptr-declarator
ptr-operator ptr-declarator
noptr-declarator:
declarator-id attribute-specifier-seqopt
noptr-declarator parameters-and-qualifiers
noptr-declarator [ constant-expressionopt] attribute-specifier-seqopt
( ptr-declarator )
和ptr-operator:
* attribute-specifier-seqopt cv-qualifier-seqopt
& attribute-specifier-seqopt
&& attribute-specifier-seqopt
nested-name-specifier * attribute-specifier-seqopt cv-qualifier-seqopt
因此这个声明int* a[5];
可以写成int ( * ( ( a )[5] ) );
即 ( ( a )[5] )
是一个 noptr 声明符和 ( * ( ( a )[5] ) )
是 ptr-operator ptr-declarator。一个指向 5 个整数数组的指针的声明看起来像
int ( *a )[5];
关于c++ - 如何从 C++ 标准推断数组 [] 的优先级高于指针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67257983/