why i can't write code like this:"int* p[]=new int*[3]"
and must write" int* p;p=new int[3];"
sorry my english not very will,i hope you can read it.
thanks for help.
This will create an array of 3 'CandyBar' objects. It will then return a pointer to the first element in that array.
Therefore the expression evaluates to this type: CandyBar*
CandyBar* p= new CandyBar [3];
This works because you are assigning that 'new' expression to 'p', which is of type CandyBar*. The type matches, therefore it is legal.
CandyBar* p[] = new CandyBar[3];
This does not work because you are assigning that expression to an array and not a pointer.
It's like doing this: int foo[] = 6; it doesn't make sense -- you can't assign a singular value to a whole array.