【发布时间】:2012-01-12 10:14:36
【问题描述】:
我想创建一个如下所示的二维数组。
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];)
【问题讨论】:
-
char (*p)[640] = new char[480][640];请注意,T的二维数组与指向T数组的指针数组不同。哦,宁可使用std::vector而不是原始new。干杯&hth., -
是的,
std::vector<std::array<char, 640> > dog(480); -
@Mooing Duck:它涵盖了 640x350 和 640x480 的分辨率,但这样混合
vector和array确实有点奇怪。我想我会一直使用vector,忘记使用array可能进行的微优化,并作为额外的奖励获取适用于更多当前编译器的代码。干杯,
标签: c++