C++数组引用问题

来源:百度知道 编辑:UC知道 时间:2024/07/01 00:22:20
c++primer 4th 里面有这句话:the type specifier can denote a built-in data or class type. With the exception of reference,the element type can also be any compound type. there are no arrays of references.这句数组不能用引用,什么意思,在P110页。
在VC里可以用啊,比如:
int a[10];
int (&b)[10]=a;
这是正确的,为什么书上这么说。

单纯从这句话的意思,我觉得他说的是不能有引用数组,而不是数组引用啊。
即是说,一个数组的成员不能是引用;而不是说,不能引用一个数组~~~我是这样理解的。。。

数组名本来就是地址,引用传递的其实也是地址
int a;
int &b=a; //这句话的实际含义是int const * b=&a;

是这样的.你这么用当然可以,因为那不叫引用,叫取地址.&同时是引用符号,也是地址符号
但是,如果你写一个函数,参数里引用数组的话是不正确的.一个函数的参数可以用其他类型的引用,但是不能用数组的引用,只能用数组的指针.