首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

const_cast有关问题

2012-02-09 
const_cast问题?intmain(){constinta1int*pconst_cast int* (&a)*p2cout a endlcout *p

const_cast问题?
int   main()
{
const   int   a   =   1;
        int   *p   =   const_cast <int*> (&a);
        *p   =   2;
 
        cout   < <a < <   endl;
        cout   < <*p   < <   endl;

        cout   < <&a   < <   endl;
        cout   < <p   < <   endl;
}

result:
1
2
0x1111
0x1111




[解决办法]
cout < <a < < endl;
004113F4 mov esi,esp
004113F6 mov eax,dword ptr [__imp_std::endl (4182A8h)]
004113FB push eax
004113FC mov edi,esp
004113FE push 1 // 看这里,编译器优化直接用 1 替换a了 :)

........................

热点排行