【发布时间】:2013-04-14 07:22:38
【问题描述】:
-
定义 int 和指向 int 的指针:
int i = 22, *p = &i; -
定义低级和顶级const指针:
const int *const cp = p;(2) 没问题 - 无权更改 (of i) 值的 const 点
-
定义一个指向low+top-level const的指针:
const int **const cp_2_p = &p;(3) 不行,为什么?
error C2440: 'initializing' : cannot convert from 'int **' to 'const int **const
我希望能够定义一个指向 int 的指针的指针,我无法更改它指向的地址,也无法更改它指向的地址。
【问题讨论】:
-
“高”和“低”级别指针是什么意思?
-
另请参阅here,了解为什么将
int **转换为int const **是个坏主意。 -
@KirilKirov - 不是高低级指针 -> 高和/或低级常量;但我错了,它被称为“顶级”和“低级”;顶级意味着您不能更改地址。低级意味着您不能更改该地址中的值。
-
@zehelvion 你倒退了。低级 const 表示地址不能更改,顶级 const 表示值不能更改。
标签: c++