这个冒号在枚举声明中起什么作用? [英] What does this colon do in an enum declaration?

查看:361
本文介绍了这个冒号在枚举声明中起什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了这个问题,以为有人必须问过这个问题。我没有得到任何结果,因此,如果有的话,请发布链接并随时关闭问题。

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 close the question.

我在 EASTL

enum : size_type {   // size_type = size_t                   
                npos     = (size_type)-1,
                kMaxSize = (size_type)-2
            };

我从未遇到过像 enum 这样的声明那。在这种情况下,是做什么的?

I have never encountered an enum declaration like that. What does the : do in this case?

推荐答案

Microsoft扩展,使您可以选择枚举值的基本类型。例如,它使您可以指定值是无符号的(Microsoft的编译器通常默认选择带符号的),或者它们仅占用8或16位(Microsoft通常默认为32位)。

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).

语法记录在这里: http:// msdn。 microsoft.com/en-us/library/2dzy4k6e(v=VS.100).aspx ,但我找不到它实际作用的官方文档。

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添加了类似的功能,但语法略有不同。在C ++ 11中,您可以这样编写:

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 .. };

这篇关于这个冒号在枚举声明中起什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆