【问题标题】:What's the differences between `int*[1]` and `int(*)[1]`?`int*[1]` 和 `int(*)[1]` 有什么区别?
【发布时间】:2018-08-26 08:38:24
【问题描述】:
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

为什么t2[0](/t1) 不可赋值?

int*[1]int(*)[1] 有什么区别?

更新:

int n[1];
t2 = &n; // ok

【问题讨论】:

    标签: c++ c++11 type-conversion type-safety using-declaration


    【解决方案1】:

    int*[1]是一个长度为1的数组,其元素为int*

    int(*)[1] 是一个指针,指向数组int[1]。因此t2[0] 是一个数组int[1],它是不可赋值的。

    【讨论】:

    • @szxwpmj 很明显,你期待什么?
    • @szxwpmj 为什么会这样? t1 是指向整数的指针数组,而不是整数数组
    猜你喜欢
    • 1970-01-01
    • 2014-06-07
    • 1970-01-01
    • 2016-04-22
    • 2015-01-06
    • 2018-11-15
    • 1970-01-01
    • 2020-05-05
    • 2015-11-04
    相关资源
    最近更新 更多