Why isn't it legal to convert “pointer to pointer to non-const” to a “pointer to pointer to const”

前端 未结 5 1032
借酒劲吻你
借酒劲吻你 2020-11-22 11:03

It is legal to convert a pointer-to-non-const to a pointer-to-const.

Then why isn\'t it legal to convert a pointer to pointer to non-const to a

5条回答
  •  名媛妹妹
    2020-11-22 11:20

    From the standard:

    const char c = 'c';
    char* pc;
    const char** pcc = &pc;   // not allowed
    *pcc = &c;
    *pc = 'C';                // would allow to modify a const object
    

提交回复
热议问题