【发布时间】:2018-07-16 09:09:06
【问题描述】:
我正在尝试创建对数组的引用。
它是这样工作的:
typedef int array_type[100];
int main() {
int a[100];
array_type &e = a; // This works
}
但后来我试图删除typedef,并让同样的事情正常工作。没有成功。
int main() {
int a[100];
// int[100] &e = a; // (1) -> error: brackets are not allowed here; to declare an array, place the brackets after the name
// int &e[100] = a; // (2) -> error: 'e' declared as array of references of type 'int &'
}
我对@987654324@ 的解释有什么问题?我怎样才能删除typedef,仍然获得相同的功能。
【问题讨论】:
-
我建议保留 typedef - 它极大地提高了可读性
-
我试图了解 typedef 的工作原理。因此尝试将其删除。
标签: c++ arrays c++11 reference typedef