我需要帮助来弄清楚该代码有什么问题:
class DatabaseEngine
{
protected:
DatabaseEngine();
static DatabaseEngine* m_DatabaseEngine;
public:
static DatabaseEngine& instance();
void do_something();
};
cp:
#include "databaseengine.h"
DatabaseEngine* DatabaseEngine::m_DatabaseEngine=nullptr;
DatabaseEngine::DatabaseEngine()
{
}
static DatabaseEngine& DatabaseEngine:: instance()
{
if(m_DatabaseEngine==nullptr)
{
m_DatabaseEngine=new DatabaseEngine;`enter code here`
}
return *m_DatabaseEngine;
}
void DatabaseEngine::do_something()
{
}
用户窗口.cpp:
#include "databaseengine.h"
UsersWindow::UsersWindow(QWidget *parent) :
QWidget(parent),
ui(new Ui::UsersWindow)
{
ui->setupUi(this);
DatabaseEngine::instance().do_something();
}
UsersWindow::~UsersWindow()
{
delete ui;
}
userswindow.obj:-1: 错误: LNK2019: 无法解析的外部符号“public: static class DatabaseEngine & __cdecl DatabaseEngine::instance(void)” (?instance@DatabaseEngine@@SAAAV1@XZ) 在函数“public: __thiscall UsersWindow: :UsersWindow(class QWidget *)" (??0UsersWindow@@QAE@PAVQWidget@@@Z)
userswindow.obj:-1:错误:LNK2019:无法解析的外部符号“public: void __thiscall DatabaseEngine::do_something(void)” (?do_something@DatabaseEngine@@QAEXXZ) 在函数“public: __thiscall UsersWindow::UsersWindow(class QWidget) 中引用*)" (??0UsersWindow@@QAE@PAVQWidget@@@Z)
谢谢