What does this "new" mean?

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
hi ZED0815
it seems the tutorial not include this case. :(
What is your code supposed to do? I never saw new used like this---And what is "max"??
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 
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.
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
oh, the first line is wrong, I forgot the "*".
Topic archived. No new replies allowed.