使用“new”创建2D数组? [英] Create 2D array with "new"?

查看:172
本文介绍了使用“new”创建2D数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个类似以下的二维数组。

I want to create a 2D array like the following.

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

新? (不使用calloc,malloc或 char dog [480] [640];

what do I need to do using "new"? (not using calloc, malloc or char dog[480][640];)

推荐答案

这样的东西:

char **dog = new char *[480];
for (int i = 0; i < 480; i++)
    dog[i] = new char[640];

删除时也一样,但循环先。

And the same when deleting, but then the loop first.

这篇关于使用“new”创建2D数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆