c++ - 关于简历分解的困惑

标签 c++ language-lawyer

根据这样的规则:
cv-decomposition

A cv-decomposition of a type T is a sequence of CVi and Pi such that T is

"CV(0) P(0) CV(1) P(1) ... CV(n-1) P(n-1) CV(n) U " for n ≥ 0

该规则的示例是:

Example: The type denoted by the type-id const int ** has three cv-decompositions, taking U as “int”, as “pointer to const int”, and as “pointer to pointer to const int”.

根据上面的表格,我可以理解Uint CV(n) 表示const ,但是我不明白为什么它还说 pointer to const int可以表示U , pointer to pointer to const int可以表示U ,我对上面表格的理解是U始终表示 unqualified-cv 基础类型。

我的问题:

  1. 为什么示例显示 U可以表示pointer to const intpointer to pointer to const int ,不是U应表示 unqualified-cv 基础类型?

  2. 上面写着A cv-decomposition is a sequence of CVi and Pi ,为什么const int **有三个cv-decompositions ?根据上面的表格,有两个Pi ,即P(0)P(1) ,分别是最后一个 *倒数第二个* ,以及相应的CV(i)是空的。所以我认为类型 const int ** ,有两个cv-decompositions ,为什么three

最佳答案

U 表示原始类型,其中零个或多个最外层“指针”与其相邻的“const”一起被删除。使用 const int ** 可以通过三种方式实现此目的。

  • U 是指向 const int 的指针(没有删除任何内容)
  • U 是指向 const int 的指针(删除了一个“指向”的指针)
  • U 是 int(两个“指针”连同其后的“const”一起被删除)

因此存在三个分解。

关于c++ - 关于简历分解的困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63097296/

相关文章:

c - 将 char * 重新解释为用于只读操作的另一种原始类型的数组的任何合法方法?

c++ - unsigned(-0.0) 的行为是否在 C++ 中定义?

c++ - 如何解决Readfile权限错误?

c++ - 如何测量一个线程的执行时间?

c++ - 为什么 cout.tellp 总是返回 -1?

c++ - C++ 编译器可以假定 const bool & value 不会改变吗?

c - C 中 printf() 中的大字段宽度

c++ - 我可以隐式创建一个可简单复制的类型吗

c++ - 帮助完成半复杂的 C++ 赋值

c++ - 在 C++ 中连接#define