Skip to content

Instantly share code, notes, and snippets.

@enghqii
Created October 25, 2014 21:04
Show Gist options
  • Save enghqii/b00b03b98d6f999f14ce to your computer and use it in GitHub Desktop.
Save enghqii/b00b03b98d6f999f14ce to your computer and use it in GitHub Desktop.
Dynamic 3rd dimension array alloc in C++
#include <iostream>
using namespace std;
#define SAFE_DELETE_ARRAY(ptr) { if(ptr) { delete [](ptr); (ptr)=NULL; } }
int main(){
// alloc 'team'
int*** team = new int**[1001];
for(int x = 0; x < 1001; x++){
team[x] = new int*[16];
for(int y = 0; y < 16; y++){
team[x][y] = new int[16];
}
}
// deal with 'team'
// delete 'team'
for(int x = 0; x < 1001; x++){
for(int y=0;y<16;y++){
SAFE_DELETE_ARRAY(team[x][y]);
}
SAFE_DELETE_ARRAY(team[x]);
}
SAFE_DELETE_ARRAY(team);
}
@enghqii
Copy link
Author

enghqii commented Oct 25, 2014

int team[1001][16][16];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment