标准转化:资格转换

时间:2010-11-25 05:28:23

标签: c++

这是ISO的要点:标准转换:数组到指针的转换:4.4美元:资格转换/第5点

    A multi-level pointer to member type, or a multi-level mixed pointer and
     pointer to member type has the form:
           cv 0 P 0 to cv 1 P 1 to . . . cv n − 1 P n − 1 to cv n T
    where P i is either a pointer or pointer to member and where T is not a
    pointer type or pointer to member type.

任何人都可以解释一下。如果有可能举个例子.. 对于那种形式实际意味着什么。任何人都可以这样做吗? 同样..该部分有不同的形式(资格转换)

2 个答案:

答案 0 :(得分:3)

多级指针是指向指针的指针。

变量通常可以是constvolatile(这些变量称为 cv-qualifiers )。当你有一个指针时,指向数据和指针本身都可以有cv限定符。当你有一个多级指针时,任何级别都可以有cv-qualifiers。

例如:

int i1 = 1;
const int i2 = 2;
int * p1 = &i1; // p1 is a non-constant pointer to a non-constant int
int * const p2 = &i1; // p2 is a constant pointer to a non-constant int
int const * p3 = &i2; // p3 is a non-constant pointer to a constant int
const int * p4 = &i2; // same as p3
int const * const p5 = &i2; // p5 is a constant pointer to a constant int
int * * pp1 = &p1; // non-const pointer to non-const pointer to non-const int
int * * const pp2 = &p1; // const pointer to non-const pointer to non-const int
int * const * pp3 = &p2; // non-const pointer to const pointer to non-const int
int const * * pp4 = &p3; // non-const pointer to non-const pointer to const int
// etc.

答案 1 :(得分:1)

他们只是说你可以有一个指向指向指针的指针的指针......指向指针以外的东西。在此过程中的每个步骤中,您都可以constvolatile或两者兼而有之。所以,例如,您可以:

int const * volatile *const volatile x;

这意味着x是指向const int的易失性指针的const,volatile指针。