Jump to content
  • Advertisement


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


creating an array of pointers using new ...

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

Let''s say I have: int *num; I want to turn that pointer into an array of pointers. I''ve been messing around with this for a long time, trying every possible syntax imaginable, but cannot get this to work. I just read that to create an array of pointers, the proper way is: int *num = new int(*)[x]; I''m using VC++ 6 and I get spammed with 100 errors before it stops trying to compile. Is this the incorrect way to do it and the info I read was wrong? If so, could someone provide the correct way? I''ve searched google a lot and this webpage is the only place I have seen so far that even talked about it.

Share this post

Link to post
Share on other sites
You can''t (well, you can, but we''ll assume you can''t) create an array of pointers using an integer pointer. However, you can do this:
int **Num = new int *[Count];

Of course, now you have a single dimension array of pointers. NOT a 2D array of integers. You CAN NOT do this:
int **Num = new int *[Count][Count2];

You have to use a for loop to allocate the second dimension (if that''s what you want. Of course, remember to delete it like this:
delete [] Num;

And delete each of it''s items using a for loop if you allocated them using a for loop.

[Resist Windows XP''s Invasive Production Activation Technology!]

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!