1

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?

3 Answers 3

9

The * has to come after the type-name that it modifies:

p = new int*[4]; c = new T*[4]; 
Sign up to request clarification or add additional context in comments.

2 Comments

Still, why is that not the case with the template?
@JonoRR: I don't see any templates. The second case, with a class type, is just as wrong as the first.
2

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]; 

Comments

1

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];

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.