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。
std::vector
,避免手动使用new
进行内存分配。 - tadman