《C++ GUI Qt 4编程》(第2版)57页“通过把recentFiles变量声明为静态变量,可以相当容易的解决问题”
我在mainwindow.h中把 QStringList recentFiles;修改为
static QStringList recentFiles;
保存后编译出错,
Description Resource Path Location Type
make: *** [debug] Error 2 spreadsheet line 0 C/C++ Problem
more undefined references to `MainWindow::recentFiles' follow spreadsheet line 495, external location: ./debug/mainwindow.o:D:\qt-book\chap04\spreadsheet\mainwindow.cpp C/C++ Problem
undefined reference to `MainWindow::recentFiles' mainwindow.cpp /spreadsheet line 400 C/C++ Problem
undefined reference to `MainWindow::recentFiles' mainwindow.cpp /spreadsheet line 419 C/C++ Problem
undefined reference to `MainWindow::recentFiles' mainwindow.cpp /spreadsheet line 473 C/C++ Problem
undefined reference to `MainWindow::recentFiles' mainwindow.cpp /spreadsheet line 474 C/C++ Problem
undefined reference to `MainWindow::recentFiles' mainwindow.cpp /spreadsheet line 488 C/C++ Problem
make[1]: *** [debug\spreadsheet.exe] Error 1 spreadsheet line 0 C/C++ Problem
把所有使用recentFiles地方修改为 MainWindow::recentFiles后保存编译仍然出错:
错误同上。
有什么解决办法?在c++中使用静态成员变量初始化好像不是那么容易。