C/C++ changing the value of a const

后端 未结 18 1828
醉梦人生
醉梦人生 2020-11-28 07:28

I had an article, but I lost it. It showed and described a couple of C/C++ tricks that people should be careful. One of them interested me but now that I am trying to repli

18条回答
  •  鱼传尺愫
    2020-11-28 07:36

    You probably want to use const_cast:

    int *ptr = const_cast(ptr_to_a);
    

    I'm not 100% certain this will work though, I'm a bit rusty at C/C++ :-)

    Some readup for const_cast: http://msdn.microsoft.com/en-us/library/bz6at95h(VS.80).aspx

提交回复
热议问题