• ### Announcements

#### Archived

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

# creating an array of pointers using new ...

## 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 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 on other sites
Sweet, it works. Thanks a lot

• ### Forum Statistics

• Total Topics
628293
• Total Posts
2981869

• 11
• 10
• 10
• 11
• 17