【发布时间】:2010-09-27 02:26:36
【问题描述】:
为什么会这样?:
const int i0 = 5;
//int i1 = const_cast<int>(i0); // compilation error
int i2 = (int)i0; // okay
int i3 = 5;
//const int i4 = const_cast<const int>(i3); // compilation error
const int i5 = (const int)i3; // okay
【问题讨论】:
-
你能添加编译器的错误信息吗?
-
无效使用类型为
int', which is not a pointer, reference, nor a pointer-to-data-member type invalid use of const_cast with typeconst int'的const_cast,它不是指针、引用或指向数据成员的指针类型
标签: c++ const-cast