#include <iostream>
using std::cout;
using std::endl;
void growArray(double* array, int size)
{
double* stackArray = 0;
double* newArray = &array[size * 2];
for (int i = 0; i < size * 2; i++)
{
if (i < size)
{
newArray[i] = stackArray[i];
}
else
{
newArray[i] = 0;
}
}
stackArray = newArray;
size *= 2;
delete[] array;
}
int main()
{
double* myArray = new double[3];
for (int i = 0; i<3; i++)
myArray[i] = (i + 1) * 2;
growArray(myArray, 3);
for (int i = 0; i<6; i++)
cout << myArray[i] << endl;
delete[]myArray;
return 0;
}
此行发生错误“newArray [i] = stackArray [i];” - 它表示“Project8.exe中0x00A01993处的未处理异常:0xC0000005:访问冲突读取位置0x00000000”。是什么造成的?谢谢!