I'm working on a map generator. I'm using a 2-d vector to keep the data.
Header:
class MapGenerator
{
public:
...
protected:
std::vector< std::vector<int> > map;
...
}
It's size is known once the MapGenerator is instanciated, I was wondering if there was a cleaner way to size it properly and fill it with 0's than what I currently do :
MapGenerator::MapGenerator(int dimensionX, int dimensionY)
: dimensionX(dimensionX), dimensionY(dimensionY)
{
map.resize(dimensionX);
for(int i = 0 ; i < map.size() ; i++)
{
map[i].resize(dimensionY);
fill(map[i].begin(), map[i].end(), 0);
}
}
This code work's fine, but if there's a cleaner or more optimal approach I'd like to know. I'm using GCC under MinGW and I don't think I have C++ 11 enabled.