jeudi 21 janvier 2021

Singleton Pattern Syntax Error static field does not name a non-static data member or base class

Don't angry with me. I am new in c++ and qt I have used singleton calss following the example from Gof But get Error

svgview.cpp:11:16: error: member initializer 'm_instance' does not name a non-static data member or base class

My header

#ifndef SVGVIEW_H
#define SVGVIEW_H
#include <QGraphicsView>

QT_BEGIN_NAMESPACE
class QGraphicsSvgItem;
class QSvgRenderer;
QT_END_NAMESPACE

class SvgView : public QGraphicsView
{
    Q_OBJECT

public:
    static SvgView* Instance();
    void openFile(const QString &fileName);
    QSvgRenderer *renderer() const;

private:
    static SvgView* m_instance;
    QGraphicsSvgItem *m_svgItem;
    SvgView();

};
#endif // SVGVIEW_H

cpp code:

SvgView::SvgView()
    : QGraphicsView()
    , m_svgItem(nullptr)
    , SvgView::m_instance(nullptr)
{
    setScene(new QGraphicsScene(this));
}

QT 5.14.1 minGW What i do wrong?

Aucun commentaire:

Enregistrer un commentaire