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

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。


您正在请求一个放置 new;该调用被理解为传递给 new 的指针;请参阅 https://dev59.com/uXVC5IYBdhLWcg3wpi98。 - OznOg
http://en.cppreference.com/w/cpp/language/new - Barry
1
@OznOg,你应该将评论扩展为一个完整的答案。 - R Sahu
不要忘记尽可能使用标准库容器,如std::vector,避免手动使用new进行内存分配。 - tadman
1个回答

6

6
你的回答出现了堆栈溢出。 - geza

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接