I have given an example to do what you want. In my comments below, I repeatedly ask, "Why not just call init() inside the Tile constructor?" That really is the best solution, but I show how to iterate over each element anyway using standard algorithms.
You might also consider writing a data structure to hold your vector< vector<Tile> >, so that you can make add, remove, etc. easier.
Code:
# include <vector>
# include <iostream>
# include <algorithm>
using namespace std;
class Tile {
public:
Tile() {
// Why not call init here??
init();
}
void init()
{
cout << "Init called!" << endl;
}
};
void init_tile(Tile& t)
{
/* Why not do it in the Tile constructor? */
t.init();
}
void init_row(vector<Tile>& row)
{
for_each(row.begin(), row.end(), init_tile);
}
int main()
{
vector< vector<Tile> > tiles;
/* Add some rows */
tiles.push_back(vector<Tile>());
tiles.push_back(vector<Tile>());
tiles.push_back(vector<Tile>());
/* Add some tiles */
tiles.at(0).push_back(Tile());
tiles.at(1).push_back(Tile());
tiles.at(0).push_back(Tile());
tiles.at(2).push_back(Tile());
/* Initialize here, if for some reason you can't just
do it in the constructor... */
for_each(tiles.begin(), tiles.end(), init_row);
}