相关疑难解决方法(0)

const_cast无法运行c ++?

我有以下代码:

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不在这里工作?

c++ const-cast

5
推荐指数
1
解决办法
467
查看次数

标签 统计

c++ ×1

const-cast ×1