源码

c – 这是const_cast的未定义行为吗?


参见英文答案 > behavior of const_cast in C++ ????????????????????????????????????3个
这里发生了什么?

const int a = 0;
const int *pa = &a;

int *p = const_cast(pa);
*p = 1;  // undefined behavior ??
cout << a << *p;  // ??

我的编译器输出0和1,但’a’的地址和’p’的值是相同的,所以我很困惑这是怎么回事.

(0)

本文由 投稿者 创作,文章地址:https://blog.isoyu.com/archives/c-zheshiconst_castdeweidingyixingweima.html
采用知识共享署名4.0 国际许可协议进行许可。除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。最后编辑时间为:9 月 26, 2019 at 09:51 上午

热评文章