我有以下课程:
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();
}
当我运行代码时,我在指令中得到以下异常:
state = s;
例外: project_name.exe中0x00F96719处的未处理异常:0xC0000006:访问冲突写入位置0x00000000。
有什么问题?
答案 0 :(得分:0)
display_obj未初始化。您需要先初始化该变量,然后才能使用它。