This question already has answers here:
How do I declare a 2d array in C++ using new?
(24个答案)
6年前关闭。
我想创建一个如下的2D数组。
但是它出错了:
使用"new"我需要做什么? (不使用calloc,malloc或
与删除时相同,但先循环。
(24个答案)
6年前关闭。
我想创建一个如下的2D数组。
char **dog = new char[480][640];
但是它出错了:
error C2440: 'initializing' : cannot convert from 'char (*)[640]' to 'char ** '
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
使用"new"我需要做什么? (不使用calloc,malloc或
char dog[480][640];
) 最佳答案
像这样:
char **dog = new char *[480];
for (int i = 0; i < 480; i++)
dog[i] = new char[640];
与删除时相同,但先循环。
关于c++ - 使用 “new”创建2D数组? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8372327/