new object

I have an object:
Ctile tile;

And i have a loop:
1
2
3
4
5
for(int r = 0;r < 50;r++) {
      

       
    }

What i want is:
Inside the loop, create a new Tile for each r(row).
1
2
3
4
5
for(int r = 0;r < 50;r++) {
      
  // =>> inside here <====
       
    }



Because CTitle have 2 int
X and Y.

So Y will be = r.
and X = l, for the other loop.
Last edited on
There are numerous ways to do this. The easiest would be to have a container store them all such as a std::vector. You could also use dynamic arrays if you really wanted to.
i know how to use a vector like TileList and push the Tile.
But i don't know how to create a new Tile inside the loop for each new r.
Last edited on
Shouldn't you create a new tile for each column? Something like:
1
2
3
4
5
6
7
8
9
10
std::vector<std::vector<Tile> > map;
for(int row = 0; row < rows; ++row)
{
    std::vector<Tile> tempRow;
    for(int column = 0; column < columns; ++column)
    {
        tempRow.emplace_back(column, row, TILEID); //x, y, type of tile
    }
    map.push_back(tempRow);
}
Last edited on
good
CMapGen.cpp:28:24: error: redeclaration of ‘std::vector<CTile> row’
std::vector<CTile> row;
^
CMapGen.cpp:26:9: error: ‘int row’ previously declared here
for(int row = 0; row < rows; ++row)
^
Well, the error is pretty straight forward. I didn't realize when I typed it up earlier but I wasn't telling you what to use it was an example of how you could do it.
I'll test here.
Last edited on
Topic archived. No new replies allowed.