c ++中的特殊枚举

Bre*_*men 0 c++ enums struct initialization

在图书馆,我遇到了一个奇怪的结构,作为枚举:

typedef struct SetControl
{
  const static uint16_t RC_MODE_ERROR;
  const static uint16_t RELEASE_CONTROL_SUCCESS;
  const static uint16_t OBTAIN_CONTROL_SUCCESS;
  const static uint16_t OBTAIN_CONTROL_IN_PROGRESS;
  const static uint16_t RELEASE_CONTROL_IN_PROGRESS;
  const static uint16_t RC_NEED_MODE_F;
  const static uint16_t RC_NEED_MODE_P;
  const static uint16_t IOC_OBTAIN_CONTROL_ERROR;
} SetControl;
Run Code Online (Sandbox Code Playgroud)

成员不会在任何地方初始化,但即使RC_MODE_ERROR等于0,RELEASE_CONTROL_SUCCESS等于1,依此类推.我知道因为我用printf记录了它.到目前为止我还没有看到类似的东西.为什么它甚至可以工作(我认为值默认情况下会被随机数据初始化,或者0)?这个超标准有增值enum吗?我将非常感谢所有的帮助.

gsa*_*ras 7

首先,这不是枚举,这是一个结构.这些是不同的概念,但我想你知道,只是对这里的用法感到困惑.

预期为一个结构的成员被分配到这些值(如例如将与发生枚举).

我很确定这些成员在代码中的某个地方初始化,或者它们是宏,因此在某处定义.


在搜索Github之后,它们被初始化,如下所示:

const uint16_t DJI::OSDK::ErrorCode::ControlACK::SetControl::RC_MODE_ERROR = 0x0000;
const uint16_t DJI::OSDK::ErrorCode::ControlACK::SetControl::RELEASE_CONTROL_SUCCESS = 0x0001;
const uint16_t DJI::OSDK::ErrorCode::ControlACK::SetControl::OBTAIN_CONTROL_SUCCESS = 0x0002;
const uint16_t DJI::OSDK::ErrorCode::ControlACK::SetControl::OBTAIN_CONTROL_IN_PROGRESS = 0x0003;
const uint16_t DJI::OSDK::ErrorCode::ControlACK::SetControl::RELEASE_CONTROL_IN_PROGRESS = 0x0004;
const uint16_t DJI::OSDK::ErrorCode::ControlACK::SetControl::RC_NEED_MODE_F = 0x0006;
const uint16_t DJI::OSDK::ErrorCode::ControlACK::SetControl::RC_NEED_MODE_P = 0x0005;
const uint16_t DJI::OSDK::ErrorCode::ControlACK::SetControl::IOC_OBTAIN_CONTROL_ERROR = 0x00C9;
Run Code Online (Sandbox Code Playgroud)

dji_error.cpp中.