Reputation: 21374
If I have:
int **p;
why can't I do this?
p = new *int[4];
but if I have:
class T {...}
T **c;
c = new *T[4];
is that correct?
Upvotes: 1
Views: 109
Reputation: 27577
You're trying to multiply the keyword new
with the type (int
or T
)! To say you want a new
array of pointers to int
:
p = new int*[4];
or an array of pointers to T
:
c = new T*[4];
Upvotes: 1
Reputation: 254631
The *
has to come after the type-name that it modifies:
p = new int*[4];
c = new T*[4];
Upvotes: 9
Reputation: 14510
No it is not correct.
the *
must go after the type-name.
Then it should be:
p = new int*[4];
And
c = new T*[4];
Upvotes: 2