void func1(){
const int** pp;//2次*(因为const的右边有出现了2次*)后,禁止赋值
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;//2次*(因为const的右边有出现了2次*)后,禁止赋值
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;//1次*(因为const的右边有出现了1次*)后,禁止赋值
pp=(int *const*)(new int *[1]);
//pp[0]=new int[1];//error: assignment of read-only location
pp[0][0]=0;
}
int main(){
return 0;
}
C++中的const在多维指针中的应用
最新推荐文章于 2022-04-04 03:48:57 发布