Jump to content
  • Advertisement


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


2D Array of Objects using new??

This topic is 5865 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
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

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!