c++ - How to delete this 2-dimensional array of pointers? Making a destructor -
malla = new celula**[n + 2]; for(int = 0 ; < 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 code , allocate memory (i want n*m array of pointers celula, okay? need destructor.
now don't know how access object in array and:
malla[i][j].setestado(true); doesn't work.
seriously consider advice of @konrad's . if anyhow want go raw array's , can :
to deallocate :
for(int = 0 ; < n + 2 ; ++i) { for(int j = 0 ; j < m + 2 ; ++j) delete[] malla[i][j] ; delete[] malla[i]; } delete[] malla; to access object :
malla[i][j][_m].setestado(true); edit :
if malla[i][j] pointer object destructor/deallocation :
for(int = 0 ; < n + 2 ; ++i) { for(int j = 0 ; j < m + 2 ; ++j) delete malla[i][j] ; delete[] malla[i]; } delete[] malla; access object/member can done : (*malla[i][j]).setestado(true); or malla[i][j]->setestado(true);
Comments
Post a Comment