Ошибка при попытке реализовать singleton c++

Пытаюсь реализовать DAO-класс generaldao как одиночку. Среда - QtCreator 4.15.0

Заголовочный:

#ifndef GENERALDAO_H
#define GENERALDAO_H

#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlQueryModel>
#include "lesson.h"
#include "student.h"
#include "visitings.h"

class GeneralDAO: public QObject
{
public:
    static GeneralDAO* getInstance();
    Student *getStudentByStudnum(QString studnum);
    Lesson* getLessonByGroupAndTime(QString group, QString time);
    void doSetVisit(QString studNum, int lessonId);

protected:
    GeneralDAO();
    static GeneralDAO* instance;

private:
    QSqlDatabase db;
    QSqlQueryModel* queryModel;
};

#endif // GENERALDAO_H

Реализация:

#include "generaldao.h"
#include <QDate>
#include<QDebug>

GeneralDAO *GeneralDAO::getInstance()
{
    if (GeneralDAO::instance == nullptr) {
        instance = new GeneralDAO();
    }
    return instance;
}

Student *GeneralDAO::getStudentByStudnum(QString studnum)
{
    Student* student = new Student();
//some query
    return student;
}

Lesson *GeneralDAO::getLessonByGroupAndTime(QString group, QString time)
{
    Lesson* lesson = new Lesson();
//some query
    return lesson;
}

void GeneralDAO::doSetVisit(QString studNum, int lessonId)
{
    //some query
}

GeneralDAO::GeneralDAO()
{
    db = QSqlDatabase::addDatabase("QPSQL");
    //hostname, password etc. settings
    db.open();

    queryModel = new QSqlQueryModel(this);
}

При попытке сборки выдает не совсем ясные ошибки: generaldao.obj:-1: ошибка: LNK2019: ббл«Є  ­  ­Ґа §аҐиҐ­­л© ў­Ґи­Ё© бЁ¬ў®« "protected: static class GeneralDAO * GeneralDAO::instance" (?instance@GeneralDAO@@1PEAV1@EA) ў дг­ЄжЁЁ "public: static class GeneralDAO * __cdecl GeneralDAO::getInstance(void)" (?getInstance@GeneralDAO@@SAPEAV1@XZ).

Помогите понять, где исправить, или как лучше реализовывать singleton, если такой подход считаете неверным


Ответы (0 шт):