Declaring my object as 'extern' gives "storage class specified" error

5.1k Views Asked by At

I have 3 classes - GLWidget, Window and rules. Window creates an object of GLWidget called 'm_glWidget' which I am trying to access from the class rules. I have tried using 'extern' and changing things up but nothing seems to make it work. The closest I have got is a single error which says "storage class specified for 'm_glWidget'" but I am unsure on what this means. This is my code:

Window.h

#include "glwidget.h"
#include "rules.h"

class GLWidget; class rules;

class Window : public QDialog, public Ui::frmMain
{
    Q_OBJECT;

public:

    Window(QWidget *parent = 0);

    rules *gameRules;
    GLWidget *m_glWidget;

Window.cpp

#include "rules.h"
#include "glwidget.h"

class rules; class GLWidget;

using namespace std;

Window::Window(QWidget *parent):QDialog(parent)
{

    m_glWidget = new GLWidget;
    gameRules = new rules;

rules.h

#include "windows.h"
#include "glwidget.h"

class rules{

public:

    rules();

    extern GLWidget *m_glWidget;

rules.cpp

#include "window.h"
#include "glwidget.h"

using namespace std;

rules::rules(){
}

void rules:: print(){

    cout << m_glWidget->x << endl;
}
1

There are 1 best solutions below

4
On

How about this?

#include "windows.h"
#include "glwidget.h"

class rules{

public:
    rules(GLWidget *glWidget)
        : m_glWidget(glWidget)
    {
    }

    GLWidget *m_glWidget;