#include <iostream>
#include <vector>
using namespace std;
class Soldier{
public:
Soldier(char c){
type = c;
}
char type;
};
int main() {
const int armies = 3;
const int soldiers_in_army = 5;
//a 2d vector of armies and its soldiers
vector< vector<Soldier> > *armys = new vector< vector<Soldier> >(armies, vector<Soldier>(soldiers_in_army, Soldier('@')));
//making a pointer array
Soldier **deployment = new Soldier*[armies*soldiers_in_army];
//test if it works
cout << "the third soldier of the second army is of type " << (*armys)[1][2].type << endl;
//initializing the pointers of the deployment array to make them point to the Object through the vector.
deployment[1 * (armys->size()) + 2] = &(*armys)[1][2];
cout << "the third soldier of the second army is of type " << deployment[1 * (armys->size()) + 2]->type << endl;
// (*deployment)[1 * (armys->size()) + 2] = (*armys)[1][2];
// cout << "the third soldier of the first army is of type " << (*deployment)[1 * (armys->size()) + 2].type << endl; return 0;
// initialize the whole array of pointers
for(int i = 0; i<armys->size(); i++)
for(int j = 0; j<(*armys)[i].size(); j++)
deployment[i *soldiers_in_army + j] = &(*armys)[i][j];
// change some values
(*armys)[0][1] = (*armys)[1][1] = (*armys)[2][1] = Soldier('C'); // captain
(*armys)[0][4] = (*armys)[1][3] = (*armys)[2][2] = Soldier('H'); // horsemen
// display original
for(int i = 0; i<armys->size(); i++) {
for(int j = 0; j<(*armys)[i].size(); j++)
cout << (*armys)[i][j].type << " ";
cout << endl;
}
// display via pointers
for(int i = 0; i<armies*soldiers_in_army; i++) {
if(i%soldiers_in_army == 0)
cout << endl;
cout << deployment[i]->type << " ";
}
}