我正在开发一个 GUI 应用程序。我有一个主窗口。主窗口有一个信息窗口,用于记录当前操作的一些基本信息,例如在做什么,需要多长时间。代码如下:
class InfoWindow
{
public:
InfoWindow();
void Record(const string& info);
};
class MainWindow
{
public:
void OperationInMainWindow()
{
// Perform the operation.
...
// Record the operation information (okay here since m_infoWindow is
// accessible.
m_infoWindow.Record(...);
}
private:
InfoWindow m_infoWindow;
// Many other windows. Other windows have also operations whose information
// need to record. And getting worse, the other windows have children
// windows who have to record operation information in the main window's
// info window.
OtherWindow1 m_otherWindow1; //
OtherWindow2 m_otherWindow2;
...
};
如何让信息记录更容易?我尝试对信息窗口使用单例,但不是很满意,因为信息窗口的生命周期应该由主窗口控制。非常感谢!!!