我有以下代码:
const int k=1;
int *p=const_cast<int *>( &k);
cout<<"k before="<<*p<<endl;
*p=10;
*const_cast<int *>( &k)=12;
cout<<"k after="<<k<<endl;
Run Code Online (Sandbox Code Playgroud)
输出是:
k before=1
k after=1
Run Code Online (Sandbox Code Playgroud)
为什么const const不在这里工作?