这可能是一个非常简单的问题,但我已经搜索了一段时间,但似乎无法弄清楚。我正在尝试在类中初始化一个常量变量常量指针。以下是头文件:
class Scheduler{
public:
Scheduler();
explicit Scheduler( unsigned long * );
private:
const unsigned long *const thresh;
};
这是该类的构造函数
Scheduler::Scheduler( unsigned long * threshold ):
thresh(threshold)
{}
当我尝试编译这段代码时,遇到了以下错误:
scheduler.cpp: In constructor ‘Scheduler::Scheduler()’:
scheduler.cpp:3: error: uninitialized member ‘Scheduler::thresh’ with ‘const’ type ‘const long unsigned int* const’
在线上多个来源讨论构造函数中常量成员变量时,都指向使用初始化列表。我认为我正在按照要求做,但显然仍然不好。有谁能看出问题在哪里吗?