首页 > 代码库 > An error from other projects which impress me most

An error from other projects which impress me most

I cannot remember what the specific c++ project is, but what impressed me most is the definition of constant pointer.

If we want to define a pointer which the address content is able to change, we can‘t use char const * p, for example:

  1. char const *p;  
  2. p=str;  
  3. *p=‘n‘;  

we will get an error message:

错误: 向只读位置‘*p’赋值

 

char * const p; //define a pointer which the address is unable to change
char const * p;//define a pointer which the address content is unable to change 
const char *p; //the same as char const *p

An error from other projects which impress me most