我想将一些定义数据包ID的枚举映射到所述数据包的大小。我知道做到这一点的简单方法是数组。为了提高可读性,我希望枚举和表在同一文件中彼此相邻。
我的头文件
internal.vector_tile.Tile
这会导致以下编译时错误
class packetFactory
{
public: enum packetType
{
ACK = 0x00,
ECU_READ = 0x01,
...
RF_NAMED_INCIDENT_B = 0x06,
HOW_MANY_VARIETIES = 0x07
};
const static int packetSizes[HOW_MANY_VARIETIES] ={
SIZEOF_ACK_PACKET,
SIZEOF_INVOKE_ECU_READ_PACKET,
...
SIZEOF_RF_INVOKE_GET_ECTM_DATA_BLOCK_PACKET};
我在表定义中添加了'constexpr'作为错误提示;现在显示为:
a "‘constexpr’ needed for in-class initialization of static data
member ‘const int packetFactory::packetSizes [7]’ of non-integral
type [-fpermissive]"
我收到以下链接时间错误
constexpr static int packetSizes[HOW_MANY_VARIETIES] = {
argle bargle如何解决此问题。