• Advertisement

Archived

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

2D Array of Objects using new??

This topic is 5651 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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

  • Advertisement