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

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -