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)
但是,编译器说:
Run Code Online (Sandbox Code Playgroud)A value of type 'float' cannot be used to initialize a value of type float* .
我在这里错过了什么?我正在使用VS2015社区IDE.
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 之间的区别在评论中指出