小编Jud*_*dge的帖子

const传播到std ::指针数组

为什么std::array在这里以不同方式实例化数据类型

using T = const int *;
std::array<T, 4> x = { &a, &b, &c, &d }; // name: class std::array<int const *,4>
x[0] = &c; // OK    : non-constant pointer
*x[0] = c; // Error : constant data
Run Code Online (Sandbox Code Playgroud)

相比这里?

using T = int *;
std::array<const T, 4> x = { &a, &b, &c, &d }; // name: class std::array<int * const,4>
x[0] = &c; // Error : constant pointer
*x[0] = c; // OK    : non-constant data …
Run Code Online (Sandbox Code Playgroud)

c++ arrays pointers const type-deduction

7
推荐指数
1
解决办法
402
查看次数

标签 统计

arrays ×1

c++ ×1

const ×1

pointers ×1

type-deduction ×1