new(float*)[]和new float*[]之间的区别

Nib*_*jee 3 c++ arrays pointers

有什么区别: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. 
Run Code Online (Sandbox Code Playgroud)

同样,

float* pB1 = new float[3]; // compiles successfully.

float* pB2 = new (float)[3] //Gives an error. Shouln't it return an array of floats ?
Run Code Online (Sandbox Code Playgroud)

但是,编译器说:

A value of type 'float' cannot be used to initialize a value of type float* .
Run Code Online (Sandbox Code Playgroud)

我在这里错过了什么?我正在使用VS2015社区IDE.

Ozn*_*nOg 6

float* pB1 = new float[3];
Run Code Online (Sandbox Code Playgroud)

正在分配一个float数组

float* pB2 = new (float)[3]
Run Code Online (Sandbox Code Playgroud)

要求分配一个数组?在'浮动'位置(这是没有意义的),这是你得到的错误.这是放置新语法,请参阅更多信息这里新的(float*)[]和新的float*[]http://en.cppreference.com/w/cpp/language/new 之间的区别在评论中指出

  • 你的答案包含堆栈溢出 (5认同)