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

前端 未结 5 1096
借酒劲吻你
借酒劲吻你 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:19

    Just since nobody has posted the solution, here:

    char *s1 = 0;
    const char *s2 = s1; // OK...
    char *a[MAX]; // aka char **
    const char * const*ps = a; // no error!
    

    (http://www.parashift.com/c++-faq-lite/const-correctness.html#faq-18.17 for why)

提交回复
热议问题