c++ - 初始化 const 类成员,错误 : declaration does not declare anything

标签 c++

我正在尝试在构造函数的成员初始化列表中初始化 const 成员变量。

我收到以下错误:

error: declaration does not declare anything [-fpermissive]
    const uint32_t LEDS
          ^

我的代码:

#include <unistd.h>

class BaseAddr {
public:
    BaseAddr():
        LEDS      (0x41200000),
        SW1       (0x41210000), // switch 1
        SW2       (0x41220000), // switch 2
        AXI_BRAM  (0x40000000), // 128 registers
        AXI_DUMMY (0x43c00000)  // 16 registers, 4 lsb are connected with leds
    { /* nop */ }

    virtual ~BaseAddr() {}

    const uint32_t LEDS;
    const uint32_t SW1;
    const uint32_t SW2;

private:
    const uint32_t AXI_BRAM;
    const uint32_t AXI_DUMMY;
};

为什么会出现这个错误?

最佳答案

我要说你有一个宏 LEDS 定义如下:

#define LEDS

现在您的成员声明变为:

const uint32_t;

这会正确触发错误,如图所示 here .

关于c++ - 初始化 const 类成员,错误 : declaration does not declare anything,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22404868/

相关文章:

c++ - 如何通过boost property_tree加密xml文件?

c++ - 用于 IVR 应用的 SIP RTP 栈

c++ - 本地数组的性能和安全性作为参数

C++ 单例惰性初始化实现和链接似乎有冲突

c++ - 为什么模板参数中的双冒号有效?

c++ - Boost 记录器链接问题

c++ - 完美包装一个函数

c++ - 如何通过 C++ 库读取多帧 DICOM 文件?

c++ - VC++ 缺少类型说明符 - 假定为 int。注意 : C++ does not support default-int

c++ - 返回你自己内部拷贝的正确方法是什么?