是否可以使用 'using' 来声明对 3 个整数类型别名的引用?

Is it possible to use 'using' to declare reference to 3 integers type alias?

我得到了一个练习,我需要为 'reference to 3 integers' 使用类型别名。尽管我使用 typedef 获得了成功,但我无法通过 c++11 引入的 using 复制它。

代码:

typedef int (& int_ref)[3]; \success

using int_ref2 = (int &) [3]; \error

我是不是应该使用类似...

using int_ref2 = int [3];

int_ref2 & iruvar ...

比较这两个声明

typedef int (& int_ref)[3]; \success

using int_ref2 =  (int &) [3]; \error 

如您所见,存在差异:在第二个声明中,类型说明符 int 在括号内。

所以放在括号外

using int_ref2 =  int( & )[3];

您只需要将括号外的typedef中使用的类型名称移动到相对于等式符号的左侧即可。

使用using声明的好处是风格更加严谨清晰。

例如将其与以下 typedef 声明进行比较

int typedef (& int_ref)[3];

这也是一个有效的声明。:)