读书人

C++中的const在多维指针中的施用

发布时间: 2013-02-15 15:46:56 作者: rapoo

C++中的const在多维指针中的应用

void func1(){const int** pp;//两个**后,禁止赋值pp=new const int*[1];pp[0]=new int[1];//pp[0][0]=0;//error: assignment of read-only location}void func2(){int const ** pp;//两个**后,禁止赋值pp=new const int*[1];pp[0]=new int[1];//pp[0][0]=0;//error: assignment of read-only location}void func3(){int *const * pp;//两个*后,禁止赋值pp=(int *const*)(new int *[1]);//pp[0]=new int[1];//error: assignment of read-only locationpp[0][0]=0;}int main(){return 0;}


读书人网 >C++

热点推荐