C++ 初始化二维动态数组c+时发生读取访问冲突+;
我正在为一个类(已经提交)做一个项目,但是初始化int2d动态数组时的读访问冲突仍然困扰着我,我不知道是什么导致了它C++ 初始化二维动态数组c+时发生读取访问冲突+;,c++,arrays,dynamic-arrays,C++,Arrays,Dynamic Arrays,我正在为一个类(已经提交)做一个项目,但是初始化int2d动态数组时的读访问冲突仍然困扰着我,我不知道是什么导致了它 class kMeans { public: //xyCoord struct struct xyCoord { int Label; int xCoordinate; int yCoordinate; }; //variables int K; xyCoord *Kcent
class kMeans
{
public:
//xyCoord struct
struct xyCoord
{
int Label;
int xCoordinate;
int yCoordinate;
};
//variables
int K;
xyCoord *Kcentroids;
int numPts;
aPoint *pointSet;
int numRow;
int numCol;
int **imageArray = NULL;
int changeLabel;
//constructor
kMeans(int clusterNum, int numPoints, int row, int col)
{
//initializes the row and column values
numCol = col;
numRow = row;
//Allocate the row and column as the size of the 2D array
imageArray = new int*[row];
for (int i = 0; i < row; i++)
{
imageArray[i] = new int[col];
}
//initializes the 2D array to contain all 0s
for (int i = 0; i < row - 1; i++)
{
for (int j = 0; i < col - 1; j++)
{
imageArray[i][j] = 0; //read access violation occurs here
}
}
//Allocate numPoints as the size of the array
pointSet = new aPoint[numPoints];
numPts = numPoints;
//Allocate clusterNum as the size of the array
Kcentroids = new xyCoord[clusterNum];
K = clusterNum;
//Initialize the labels for each Kcenteroid
for (int i = 0; i < K; i++)
{
Kcentroids[i].Label = i + 1;
}
}
classkmeans
{
公众:
//xyCoord结构
结构xyCoord
{
int标签;
国际协调;
国际协调;
};
//变数
int K;
xyCoord*kcentroid;
int numPts;
aPoint*点集;
int numRow;
国际货币基金组织;
int**imageArray=NULL;
int-changelab;
//建造师
kMeans(int clusterNum、int numPoints、int row、int col)
{
//初始化行和列值
numCol=col;
numRow=行;
//将行和列分配为二维数组的大小
imageArray=新整数*[行];
对于(int i=0;i|
该错误以前没有出现,但当我决定在提交之前再次运行该程序时,出现了读访问冲突,因此我不确定是什么导致了它。更改此项:
for (int j = 0; i < col - 1; j++)
for(int j=0;i
为此:
for (int j = 0; j < col - 1; j++)
for(int j=0;j
由于要检查j
的条件,而不是i
请更改此项:
for (int j = 0; i < col - 1; j++)
for(int j=0;i
为此:
for (int j = 0; j < col - 1; j++)
for(int j=0;j
既然您想检查
j
的条件,而不是i
什么是aPoint
?intj=0;i
非常非常仔细地查看这个for(intj=0;i有i
而不是j
什么是aPoint
?intj=0;i
非常非常仔细地看这一个,因为(intj=0;i
有i
而不是j