相关疑难解决方法(0)

枚举的reinterpret_cast错误

为什么我不能使用reinterpret_cast运算符进行这样的演员表?

enum Foo { bar, baz };

void foo(Foo)
{
}

int main()
{
   // foo(0); // error: invalid conversion from 'int' to 'Foo'
   // foo(reinterpret_cast<Foo>(0)); // error: invalid cast from type 'int' to type 'Foo'
   foo(static_cast<Foo>(0)); 
   foo((Foo)0);
}
Run Code Online (Sandbox Code Playgroud)

c++ enums static-cast

11
推荐指数
1
解决办法
3335
查看次数

标签 统计

c++ ×1

enums ×1

static-cast ×1