C++初始化指针数组的问题,求高人指点

我现在代码里有BYTE *imgDataBuffer[BUFSIZES]; BUFSIZES不能是变量只能是常量,比如固定值10,那么该数组有10个元素。而且我代码要求 BUFSIZES是变化的,需要BUFSIZES成为变量。那么我应该怎么去定义我这个数组呢?用new?求高手指点。
提示表达式必须为常量值。我需要这个值是变化的,从别函数传参数进来的

#include<iostream>
#include<array>
using namespace std;

int main(int argc, char* argv[])
{
int BUFSIZES =3; // åŠ¨æ€å˜åŒ–çš„
int * foo;
foo = new (nothrow) int[BUFSIZES]; // ç”¨new
if (foo == nullptr) {
// åˆ†é…é”™è¯¯
}

for (int i = 0; i < BUFSIZES; i++) foo[i] = i + 1;
for (int i = 0; i < BUFSIZES; i++) cout << foo[i] << "\t";
cout << endl;

delete[] foo; // é‡Šæ”¾å†…å­˜

system("pause");
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-10-19
你的theApp.m_filesCount是变量,数组定义在栈上分配,不能使用变量,如果要动态数组,请使用new
相似回答