[solved] Error multiple definition of static member of class

I would like to have a class member pointer static so that I can access it via classname::pointer.
In the following code titleLabel is a pointer to a QLabel that I would like to make static.
I get an error
:-1: error: mainwindowii.o:(.bss+0x0): multiple definition of `ui::titlelabel'; main.o:(.bss+0x0): first defined here

What am I doing wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef MAINWINDOWII_H
#define MAINWINDOWII_H

#include <QMainWindow>
#include <QLabel>
#include <QBoxLayout>
#include <QStyle>
#include <QDesktopWidget>
#include <QScreen>


class Game;
//class StateMachine;

namespace Ui {
class MainWindowII;
}

class MainWindowII : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindowII(QWidget *parent = nullptr);
    ~MainWindowII();

    void setGame(Game *g);
    Game *_pGame;                               // pointer to the game object
    static QLabel *titleLabel;                       // label to show the title - probably morph this to use as general purpose image display
    //QLabel *MainWindowII::titleLabel =  new QLabel(); //nullptr_t; // new QLabel(this);

private slots:

    void on_actionNew_Game_triggered();


private:
    Ui::MainWindowII *ui;

    void startNewGame();

    void initTitle();           // load the title bitmap
};

QLabel * titlelabel = new QLabel();

#endif // MAINWINDOWII_H
Last edited on
Move line 45 to the corresponding cpp file.
Doing that removes the multiple def error (thank you)
Last edited on
Topic archived. No new replies allowed.