-
2D array pointers
Hey
Ive been trying to use a 2d Array pointers heres what ive done so far im trying to create a 2d array pointer of type Obj:
[/Start of code]
struct Obj
{
float speed,x,y;
int r,g,b;
bool isDrawn;
};
class cBuilding
{
Obj **bld;
etc......
};
cBuilding::cBuidling()
{
bld = new Obj*[21]; //Pointers to 21 arrays
for (int c=0; c<21; c++)
{
bld[c] = new Obj[7]; //Creates an array for each pointer in bld array
}
}
cBuilding::~cBuilding()
{
for (int c=0; c<21; c++)
{
delete [] bld[c];
}
delete [] bld;
}
[/End of code]
it just crashes my program please help me im desperate :D
Thanks
Chris
-
-
That's not a 2d array but an array of arrays. I recommend you use a single array and dynamically dimension it into 2d, so that you can access it by bld[a+b*width];