3

I have following static declaration of memory:

void* array[5000];

How I can allocate the same memory using operator new in C++?

Derek
  • 1,104
  • 13
  • 35
BSalunke
  • 11,499
  • 8
  • 34
  • 68
  • 1
    What exactly do you want to allocate? – Chris Lutz Oct 15 '11 at 05:12
  • 2
    @kalyan: I fail to see how this question isn't suitable for SO. Many novices get a bit lost when the solution entails a double-pointer, and I'm not sure that Google would be all that helpful to a novice. – Marcelo Cantos Oct 15 '11 at 05:13
  • 1
    How is this not a decent SO question? It's how to turn a static allocation into a dynamic one (for many, it's not obvious that you need to add an extra `*` in the declaration in addition to how the `new` needs to be used with pointer). – Jim Buck Oct 15 '11 at 05:14
  • How is that localized? There's *tons* of C/C++-specific questions on here. – Jim Buck Oct 15 '11 at 05:15
  • @moderators: please abstain from such heavy-handed nuclear history revisions as the remaining rubble indicates has been done here. – Cheers and hth. - Alf Oct 15 '11 at 08:13
  • Hah, true, it now looks like Marcelo and I are talking to a ghost. :) – Jim Buck Oct 15 '11 at 18:04

2 Answers2

10
void **array = new void*[5000];
Jim Buck
  • 20,482
  • 11
  • 57
  • 74
  • 1
    Yeah, the voids were enough to confuse me because my original answer (before your edit) actually compiled! Then I realized it was wrong and deleted it. – Mysticial Oct 15 '11 at 05:16
  • Not to mention that I edited it wrong.. I deleted an asterisk instead of adding one. :) – Jim Buck Oct 15 '11 at 05:16
-2

at above there is array of pointers here is just an array of Integer.

int array = new int [5000];

sam
  • 1,363
  • 1
  • 20
  • 32