Archived

This topic is now archived and is closed to further replies.

MARS_999

2D Array of Objects using new??

Recommended Posts

I have tried to allocate memory using new for a 2D array of an object and no luck? Also if you can do this do you need to use something like this for delete?
//CFOO is a class

CFOO *foo;
foo = new CFOO[10][10];

//now do we use this kind of delete 
delete [] [] cfoo;
  

Share this post


Link to post
Share on other sites
You''ll have to do it like this:

  
// allocation

CFOO **foo;

foo = new CFOO*[10];

for (int index=0;index < 10;index++)
foo[index] = new CFOO[10];

// deallocation

for (int index=0;index < 10;index++)
delete [] foo[index];
delete [] foo;



Goblineye Entertainment
The road to success is always under construction

Share this post


Link to post
Share on other sites