gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 02:54:06 25 4
gpt4 key购买 nike

我正在尝试在构造函数的成员初始化列表中初始化 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com