我为矩阵分配了一块内存。比在循环中我记得指向行的指针。
我得到了未处理的异常:在 _tmain 循环中访问冲突写入位置 0x00557148。我做错了什么?
double **d;
#define COUNT 10
int create()
{
d = (double**) malloc(COUNT * sizeof(double*));
if (!d)
return 0;
int size = COUNT * sizeof(double);
double *_new = (double*) malloc(COUNT * size);
if (!_new)
return 0;
for (int i = 0; i < COUNT; i++) {
d[i] = _new;
_new += size;
}
return 1;
}
int _tmain(int argc, _TCHAR* argv[])
{
double *_d;
if (create()) {
for(int i = 0; i < COUNT; i++) {
_d = d[i];
for (int j = 0; j < COUNT; j++)
_d[j] = 5;
}
} else
return -1;
return 0;
}