【发布时间】:2015-11-14 05:45:32
【问题描述】:
我仍在处理我的Logger,我喜欢单例的想法,但我的 Logger 派生 frm QDialog,因此我想在我第一次调用它时处理我的 Parent QWidget* MainWindow 指针:
class Logger : public QDialog {
Q_OBJECT
private:
explicit Logger(QWidget* parent = 0);
public:
static Logger& firstInstance(QWidget* parent = 0) {
static Logger theInstance(parent);
return theInstance;
}
static Logger& instance() {
return theInstance;
}
//..
}
所以我会从我的主窗口调用Logger::firstInstance(this);。还有其他地方的 Logger::instance() 。但是我的编译器模拟了:
错误:“theInstance”未在此范围内声明: 返回实例;
在第二个instance() 方法中。
【问题讨论】:
-
好吧,正如编译器所说:在您的第二种方法中没有名为
theInstance的变量。那么编译器应该如何找到它呢? -
为什么记录器是一个对话框?对于记录器来说,这听起来很奇怪。
-
考虑开始不喜欢 Singleton 的想法...
-
@PiotrNycz 当你无法证明你的论点时,它就是声音和烟雾
-
@molbdnilo 我在单独的对话框中显示输出
标签: c++ logging static singleton overloading