如何获得枚举的基本类型? [英] How do I get the fundamental type of an enum?

查看:73
本文介绍了如何获得枚举的基本类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

带有如下声明:

enum DrawBoldMode : unsigned
{
    DBM_NONE =              0,
    DBM_ITEM =              1<<0,   // bold just the nearest line
    DBM_SECTION =           1<<1,   // bold all lines in the same section
    DBM_LINETYPE =          1<<2,   // bold all lines of the same line type
    DBM_POINTAGE =          1<<3,   // bold all lines of the same line type
};

如何获取DrawBoldMode的基础类型(即未签名)?

How can I derive the underlying type of DrawBoldMode (i.e. unsigned)?

推荐答案

它应该以 std :: underlying_type< DrawBoldMode> :: type 的形式提供。但是,我的编译器(GCC 4.6.1)似乎并未实现。

It should be available as std::underlying_type<DrawBoldMode>::type. However, my compiler (GCC 4.6.1) doesn't seem to implement that.

认为不可能用模板来实现,但是我对此可能是错的。

I think it's impossible to implement it with templates, but I could be wrong about that.

这篇关于如何获得枚举的基本类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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