这可能是一个可笑的简单问题,但我一直在寻找答案一段时间,但似乎无法弄清楚这一点。我试图初始化一个类中的常量变量常量指针。这里是头文件:类中未初始化的常量成员
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’
多种来源在线讨论成员变量的构造函数中的常量成员变量指向使用初始值设定项列表。我想我正在做我应该做的事,但显然它还是不好。任何人都可以看到有什么不对?
你的代码似乎缺少默认构造函数的实现,这是错误来自的地方。 – visitor 2010-12-03 10:24:40