我在理解如何分配到Test
阵列时遇到问题,如下所示:
int (*&Test)[10] = Parray;
Test
是对指向十个整数的指针的引用。
我得到的错误如下:如何分配数组int(*&Test)[10]?
error: incompatible types in assignment of 'int*' to 'int [10]'|.
我已经做了我的研究没有完全理解这一点。我正在阅读C++ Primer第5版。
int main() {
int arr[10];
int n = 5;
int *ptr1 = &n;
int arr2[10];
int *ptrs[10]; // ptrs is an array of ten pointers
// Parray points to an array of ten ints
int (*Parray)[10] = &arr;
// arrRef refers to an array of ten ints
int (&arrRef)[10] = arr2;
// Test is a reference to a pointer to an array of ten ints.
int (*&Test)[10] = Parray;
// How can I assign to Test[0..1..2..etc]?
// This is what I am trying to do:
Test[0] = ptr1; // Error here
return 0;
}
我该如何分配到Test[0]
等?
否测试是指向的10个整数的数组的指针的引用。 – texasbruce 2014-11-03 05:01:13
^它与'arr'类型相同。如果你想要一个指针数组,你需要使用你的“师生比”变量某处 – Aralox 2014-11-03 05:10:12
'ptr1'是未初始化的指针,它并不清楚你希望与'ptr1'和'ptrs'这里 – 2014-11-03 05:14:11