new int*[]
和new (int*)[]
:
int** pA = new int*[2] // returns a pointer to an array of pointers to int.
new (int*)[2] // what should this return ? Shouldn't it be same as the above.
同样地,
float* pB1 = new float[3]; // compiles successfully.
float* pB2 = new (float)[3] //Gives an error. Shouln't it return an array of floats ?
但是,编译器说:
A value of type 'float' cannot be used to initialize a value of type float* .
我在这里缺少什么?我正在使用VS2015社区IDE。
答案 0 :(得分:6)
float* pB1 = new float[3];
正在分配一个float
数组float* pB2 = new (float)[3]
要求分配一个数组?在'浮动'位置(这是没有意义的),这是你得到的错误。 这是展示位置新语法,请参阅评论中指出的Difference between new (float*)[] and new float*[]或http://en.cppreference.com/w/cpp/language/new更多信息