限制枚举类的位数

[an error occurred while processing the directive]

在C++14中,我想限制枚举类持有的总位数:

代码语言:javascript复制enum class InstalledCapacity : uint8_t{

None,

One_1000uF,

Two_1000uF,

Three_1000uF,

One_1F,

One_3_3F,

Reserved2,

Invalid

};

using HarvestingCapability = uint8_t;

typedef struct {

InstalledCapacity installed_capacity : 3;

HarvestingCapability harversting_capability_x_15mW : 5;

}EnergyInfo;这似乎不起作用,我得到以下警告:

代码语言:javascript复制eeprom_metadata.h:51:42: warning: '::installed_capacity' is too small to hold all values of 'enum class InstalledCapacity'

InstalledCapacity installed_capacity : 3;

^因为我的InstalledCapacity枚举类中只有7个值,所以我希望它只能使用3位。

我做错了什么,这有可能吗?首先要感谢大家!

[an error occurred while processing the directive]
Copyright © 2088 米策网游动态中心-新游测试与公会争霸 All Rights Reserved.
友情链接