xml*_*lmx -1 c++ standards casting type-conversion c++11
在入口处reinterpret_cast,cppref说:
可以将积分,枚举,指针或指向成员类型的表达式转换为其自己的类型.结果值与表达式的值相同.(自C++ 11以来)
但是,以下代码无法编译(clang 5.0 with -std=c++1z):
enum class A : int {};
int main()
{
A a{ 0 };
reinterpret_cast<int>(a); // error : reinterpret_cast from 'A' to 'int' is not allowed
}
Run Code Online (Sandbox Code Playgroud)
为什么不像reinterpret_castC++标准那样表现?
类型a是A,而不是int.语法enum class A : int使得int所述基础类型的A,这是一个特殊的关系,但不是"是一个"关系.
(static_cast将执行此转换.)