Unable to read memory - class variable

-3

I have the following classes:

Main.cpp

Display* display_obj;
void display_wrapper()
{
    display_obj->display();
}

void main(int argc, char **argv)
{
    //...
    State* s = new State(100);

    glutReshapeFunc(reshape_wrapper);
    display_obj->setState(s);
    //...
}

Display.h

class Display
{
public:
    Display(){}
    ~Display(){};

    void display();
    void setState(State*);

private:
    State* state;
};

//...

void Display::setState(State* s)
{
    state = s;
}

State.h

class State
{
public:
    State(){};
    State(int);
    ~State(){};

private:
    GLint timer;
    Floor floor;
};

State::State(int t)
{
    timer = t;

    FloorLogical floorLogical;
    floor = floorLogical.createFloor();
}

When i run the code i get the following exception in the instruction:

state = s;

Exception: Unhandled exception at 0x00F96719 in project_name.exe: 0xC0000006: Access violation writing location 0x00000000.

What is wrong?

c++
asked on Stack Overflow Dec 12, 2014 by hangwook

1 Answer

0

display_obj is not initialized. You need to initialize that variable before you can use it.

answered on Stack Overflow Dec 12, 2014 by user2970916

User contributions licensed under CC BY-SA 3.0