malla = new Celula**[n + 2];
for(int i = 0 ; i < n + 2 ; ++i){
malla[i] = new Celula*[m + 2];
for(int j = 0 ; j < m + 2 ; ++j){
malla[i][j] = new Celula[m];
}
}
I’m making this code and I allocate memory like this (I want a n*m array of pointers to Celula, is okay? Now I need a destructor.
Now I don’t know how to access to an object in this array and:
malla[i][j].setestado(true);
doesn’t work.
Seriously consider the advice of @konrad’s . If anyhow you want to go with raw array’s , you can do :
To deallocate :
To access the object :
Edit :
if
malla[i][j]is pointer to simply object then destructor/deallocation will look like :Access object/member can be done like :
(*malla[i][j]).setestado(true);ormalla[i][j]->setestado(true);