【发布时间】:2012-07-29 16:54:41
【问题描述】:
我有一个单例类,我需要一个私有成员。我希望该成员为空,直到我使用我的 setter 方法设置正确的数据。
class PlaybackHelper{
private:
PlaybackHelper();
PlaybackHelper(PlaybackHelper const&);
void operator=(PlaybackHelper const&);
playback_type type;
Note note;
public:
void setPlaybackType(playback_type aType);
static PlaybackHelper &getInstance();
};
Xcode 在我的实现文件(我正在实现我的私有构造函数)中给我一个错误,说我应该初始化我的成员:
PlaybackHelper::PlaybackHelper(){
}
error: Semantic Issue: Constructor for 'PlaybackHelper' must explicitly initialize the member 'note' which does not have a default constructor
我不明白为什么我无法做到这一点(特别是因为它没有给我以相同方式工作的 playback_type type;(枚举)成员的任何错误)我可以做些什么来离开我的请注意成员为空,直到我准备好为其赋值?
【问题讨论】:
-
Node 类型的对象没有默认构造函数,显然是在读取错误文本后。不是吗?
标签: c++ singleton initialization member default-constructor