What does this colon do in an enum declaration?

后端 未结 2 1648
囚心锁ツ
囚心锁ツ 2021-01-08 00:34

I did a search for this question thinking that somebody must have asked it before. I did not turn up any results, so if it has been, please post the link and feel free to cl

相关标签:
2条回答
  • 2021-01-08 01:14

    In C++0x, you can specify the underlying type for the enum. In this case, it will be size_type.

    (And it may be supported as an extension in other places prior to C++0x, obviously.)

    0 讨论(0)
  • 2021-01-08 01:26

    This is a Microsoft extension that lets you choose the base type of the enum values. For example, this lets you specify that values are unsigned (Microsoft's compilers usually choose signed by default) or that they only occupy 8 or 16 bits (Microsoft normally defaults to 32 bits).

    The syntax is documented here: http://msdn.microsoft.com/en-us/library/2dzy4k6e(v=VS.100).aspx but I'm not able to find official documentation of what it actually does.

    C++11 adds a similar feature, but with slightly different syntax. In C++11 you'd write it like this:

    enum MyEnum : size_type { .. values .. };
    
    0 讨论(0)
提交回复
热议问题