如何为数组类型调用new运算符

Nul*_*ptr 0 c++ types pointers new-operator

static int (*g_data)[3];

我想要的new N元素int[3].我只能这样做如下:

g_data = (int(*)[3]) new int[N*3];

我知道这没关系,使用struct将是另一种解决方案.但是,只是出于好奇,我可以直接调用newint[3],即没有类型转换?

Cub*_*bbi 5

由于g_data是指向3的1D数组的指针int,要制作N个这样的3个数组的数组,您只需使用int [N][3]:

g_data = new int[N][3];
Run Code Online (Sandbox Code Playgroud)