关于cpp reference如果忽略顶级 cv 限定符,则可以说两个指针是相同的,它们指向相同的类型。示例中还有这个示例
int (* const *)(int *) and int (* volatile *)(int *) are similar;
我想知道这些应该如何相似? AFAIK 这些表示指向函数指针的指针,为了简化它们可以重写为
using XYZ = int(*)(int *);
const XYZ *; // A
volatile XYZ *; // B
在这种情况下,A 和 B 指针不是指向不同的类型吗?
最佳答案
On cpp reference it is said that two pointers are the same if ignoring the top level cv qualifiers they point to the same type
不完全是。它说:
Informally, two types are similar if, ignoring top-level cv-qualification:
they are the same type; or
they are both pointers, and the pointed-to types are similar; or
请注意,相同与相似不同。
const XYZ *; // A volatile XYZ *; // B
Aren't A and B pointers to different types in that case?
它们确实是不同的类型。但它们很相似。
关于c++ - 类型别名和相似类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58268296/