How to change the integer type used by an enum (C++)?

前端 未结 4 2004
既然无缘
既然无缘 2021-01-03 18:49

If I have an C++ enum:

enum Foo
{
  Bar,
  Baz,
  Bork,
};

How do I tell the compiler to use a uint16_t to actually store the

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-03 19:08

    With c++11 you now have enum class, that allows you to set underlying type explicitly:

    enum class Foo: uint16_t 
    { 
       Bar,
       Baz,
       Bork,
    }; 
    

提交回复
热议问题