So I have a class that uses recursion to generate a level. Simple example of BSP dungeon generation. I'm using the code in here. But, I'm writing in C++ so I can't have a static class.
The problem is I have this, with pointer of the class in there.
#ifndef RECTANGLE_H
#define RECTANGLE_H
class Rectangle
{
public:
Rectangle(int top, int left, int height, int width);
~Rectangle();
bool split();
void generate_dungeon();
private:
static int min_size;
Rectangle* dungeon;
Rectangle* left_child;
Rectangle* right_child;
int top, left, width, height;
};
#endif
Edit
std::vector<Rectangle*> rectangles;
Rectangle root(0,0,map_height,map_width);
//std::cout<<root.split()<<std::endl;
rectangles.push_back(&root);
//std::cout<<rectangles.at(0).split()<<std::endl;
while(rectangles.size() < 5)
{
int split_idx = Rng::rand_int(0, (rectangles.size()-1));
Rectangle* to_split = rectangles.at(split_idx);
std::cout<<rectangles.size()<<std::endl;
if((*to_split).split())
{
rectangles.push_back(((*to_split)get_left()));
rectangles.push_back(((*to_split)get_right()));
}
}
root.generate_dungeon();
This solves the problem. I call clear on the std::vector
after.