C++ 什么';‘int*[1]`和‘int(*)[1]`之间的区别是什么?
为什么C++ 什么';‘int*[1]`和‘int(*)[1]`之间的区别是什么?,c++,c++11,type-conversion,type-safety,using-declaration,C++,C++11,Type Conversion,Type Safety,Using Declaration,为什么t2[0](/t1)不可分配 int*[1]和int(*)[1]之间有什么区别 更新: using T1 = int*[1]; using T2 = int(*)[1]; T1 t1; T2 t2; t1[0] = 0; // ok t2[0] = 0; // error : array type 'int [1]' is not assignable t2 = t1; // error : array type 'int [1]' is not assignable
t2[0]
(/t1
)不可分配
int*[1]
和int(*)[1]
之间有什么区别
更新:
using T1 = int*[1];
using T2 = int(*)[1];
T1 t1;
T2 t2;
t1[0] = 0; // ok
t2[0] = 0; // error : array type 'int [1]' is not assignable
t2 = t1; // error : array type 'int [1]' is not assignable
t2 = &t1; // error : array type 'int [1]' is not assignable
t2 = 0; // ok
int*[1]
是长度为1的数组,其元素为int*
int(*)[1]
是一个指针,指向数组int[1]
。因此,t2[0]
是一个数组int[1]
,它是不可赋值的。@szxwpmj很明显,你期望什么?@szxwpmj为什么会这样t1
是指向整数的指针数组,而不是整数数组
int n[1];
t2 = &n; // ok