2017-10-11 50 views
3

之間有什麼區別: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

您正在申請展示位置new;該調用被理解爲傳遞給新的指針;見https://stackoverflow.com/questions/222557/what-uses-are-there-for-placement-new – OznOg

+0

http://en.cppreference.com/w/cpp/language/new – Barry

+1

@OznOg,你應該將評論擴展到完整的答案。 –

回答