基本形式:
1. int x = 1, &r = x; -> good
2. int x = 1;
const int &r = x; -> good
3. int x = 1;
int const &r = x; -> good
4. int x, const int &r = x; -> failed
5. int x, const &r = x; -> failed
问题:
1)有什么区别:
const int &r = x and
int const &r = x
似乎没有区别。
2)如何使用4)和5)中的单一定义将const引用与其他int声明符一起编写
const int &r = x
和之间没有区别int const &r = x
。
您尝试做的事是不可能的。声明包括:
int
和const
。在大多数情况下,顺序DECL -符在DECL说明符-SEQ是无关紧要的。x
或&r = x
。通过分别将每个 init-declarator与每个 decl-specifier组合来解释该声明。因此,在单个声明中声明的所有实体都具有一个公共的decl-specifier-seq。由于const
是decl-specifier而不是声明符的一部分,因此您不能让它仅适用于声明中的一个声明符。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句