【发布时间】:2014-08-25 23:23:00
【问题描述】:
所以我在班级Map 中有一个私人成员:
char **_map;
然后我尝试将指针数组初始化为二维char 数组,如下所示:
std::vector<std::string> contents = StringUtils::split(_mapInfo.getContents(), ' ');
const int x = StringUtils::toInt(contents.at(0));
const int y = StringUtils::toInt(contents.at(1));
_map = new char[x][y];
基本上contents 向量包含两个字符串,然后我将它们转换为整数。然后我尝试初始化 map 数组,但收到此错误:
Error 1 error C2540: non-constant expression as array bound
还有这个:
Error 2 error C2440: '=' : cannot convert from 'char (*)[1]' to 'char **'
最后是这个:
3 IntelliSense: expression must have a constant value
最后一个错误引用了变量y
谁能解释发生了什么以及我该如何解决?
【问题讨论】:
-
谢谢你,回答了我的问题!