我是C ++的新手,试图理解指针机制。 我想我了解指针,const指针和指向const的指针如何工作的大多数要点,但是我无法落后于某些特定行为(我搜索了其他问题,但只发现了我已经理解的其他问题)。 指向const int的指针即使指向非const int也有效:
int i = 1;
int * iP = &i; // ofc works
const int * ciP = &i; // also works
因此,添加其他const似乎不是问题。但是在这种情况下:
int i = 1;
int * iP = &i;
int ** iPP = &iP // works as usual
const int ** ciPP = &iP // does not work event though it only adds a const to the non-const int
const int * const * ciPP2 = &iP // works again, but I totally don't understand why
所以我希望(//不起作用..)行起作用,并且(//再次起作用..)行也可以起作用(如果之前的行已经起作用),或者也不能起作用(如果之前的行已经起作用)不。我在哪里弄错了?