Ayr*_*osa 7 c++ arrays grammar declaration language-lawyer
我知道像这样的声明
int* a[5];
Run Code Online (Sandbox Code Playgroud)
声明a
为一个包含 5 个指针的数组int
。但是我如何仅通过使用 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 )
Run Code Online (Sandbox Code Playgroud)
和
ptr-operator:
* attribute-specifier-seqopt cv-qualifier-seqopt
& attribute-specifier-seqopt
&& attribute-specifier-seqopt
nested-name-specifier * attribute-specifier-seqopt cv-qualifier-seqopt
Run Code Online (Sandbox Code Playgroud)
因此这个声明
int* a[5];
Run Code Online (Sandbox Code Playgroud)
可以写成
int ( * ( ( a )[5] ) );
Run Code Online (Sandbox Code Playgroud)
这是( ( a )[5] )
一个noptr说明符 和( * ( ( a )[5] ) )
是PTR运营商PTR说明符。
一个指向 5 个整数数组的指针的声明看起来像
int ( *a )[5];
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
148 次 |
最近记录: |