What does this "new" mean?

Sep 2, 2011 at 2:27am
Dose anyone can tell me what this new do? New a ClassA with buff max?
Thanks.
1
2
ClassA *pA = NULL;
pA  = new sizeof(max) ClassA;


Last edited on Sep 2, 2011 at 7:36am
Sep 2, 2011 at 5:45am
Sep 2, 2011 at 6:11am
hi ZED0815
it seems the tutorial not include this case. :(
Sep 2, 2011 at 6:20am
What is your code supposed to do? I never saw new used like this---And what is "max"??
Sep 2, 2011 at 6:25am
Ok I'll give it a shot maybe it'll help you:

1
2
3
4
5
6
7
int max = 10; // give me 10 class objects please!
ClassA *pA = NULL; // you want a pointer here not a real instantiation - correct thing is to initialize the pointer to NULL (well done)
pA  = new ClassA[max];

[...]do stuff

delete[] pA; // important to get memory cleaned up again 
Sep 2, 2011 at 6:30am
What is your code supposed to do?
It's what I want know.
max seems is a length. Is's a int value.

your code is allocate a array of ClassA, it not same with my case.
Sep 2, 2011 at 6:34am
Well in your code even the first line is just....wrong! You cant tell an actual object to be NULL. A pointer yes, but object no! As I stated before I never saw a new directive like this before...maybe someone else has a clue on this one - I don't
Sep 2, 2011 at 6:36am
Sep 2, 2011 at 7:36am
oh, the first line is wrong, I forgot the "*".
Topic archived. No new replies allowed.