创建 Dungeon 类的实例时出现堆栈溢出错误。我觉得这是因为我的地牢课程创建了一系列房间,而我的房间创建了一系列单元格。我唯一的问题是我以前做过这个,从来没有遇到过这个问题。所以这次我做错了什么?我的阵列是否太大?我可以将我的房间阵列设置为最大 [5][3],但我希望它有一个 [5][5] 大小的房间。这是不可能的吗?
我知道堆栈溢出错误是当您用完堆栈上的内存时,但我怎么知道我何时退出该堆栈并可以重新开始?或者当某些东西从那个堆栈中取出时?
这是我关于如何设置这 3 个类的代码 (Dungeon.h):
#ifndef DUNGEON_H
#define DUNGEON_H
#include <stdlib.h>
#include <string>
#include "TextureHandler.h"
#include "Room.h"
using namespace std;
class Dungeon
{
public:
Dungeon();
~Dungeon();
private:
static const int MAX_RM_ROWS = 5; //Maximum amount of rows of rooms we can have
static const int MAX_RM_COLS = 5; //Maximum amount of columns of rooms we can have
Room rooms[5][5];
int currentDungeon; //Stores the ID of the current dungeon we are in.
int currentRoomRow; //Stores the row position in the room array for what room the player is in
int currentRoomCol; //Stores the column position in the room array for what room the player is in
protected:
};
#endif
房间.h
#ifndef ROOM_H
#define ROOM_H
#include <stdlib.h>
#include "Cell.h"
using namespace std;
class Room
{
public:
Room();
~Room();
void draw();
void setupCell(int row, int col, float x, float y, float width, float height, bool solid, vector<float> texCoords);
int getMaxRows();
int getMaxCols();
private:
static const int MAX_ROWS = 30;
static const int MAX_COLS = 50;
Cell cells[MAX_ROWS][MAX_COLS];
protected:
};
#endif
细胞.h
#ifndef CELL_H
#define CELL_H
#include <stdlib.h>
#include <vector>
#include "GL\freeglut.h"
using namespace std;
class Cell
{
public:
Cell();
~Cell();
void setup(float x, float y, float width, float height, bool solid, vector<float> texCoords);
void draw();
float getX();
float getY();
float getWidth();
float getHeight();
bool isSolid();
private:
float x;
float y;
float height;
float width;
bool solid;
vector<float> texCoords;
protected:
};
#endif