0
컴파일 오류가 발생하지 않고 다른 클래스의 하나의 클래스 포인터 배열로이 작업을 시도 할 때 오류가 발생하지 않습니다. 내가 세 가지 수업을 할 때. 나는 추락한다.다른 클래스의 포인터 포인터 배열의 클래스 포인터 배열의 세그먼트 오류
#define size 10
// single point with x and y
class singlePoint{
public:
float xCoordinate;
float yCoordinate;
};
// row of points
class pointRow{
public:
singlePoint *pointRowArray[size];
void makePointRowArray(int);
void setPointRowArray(int);
};
// “row” of row of points
class totalSquare{
public:
pointRow *totalSquareArray[size];
void makeTotalSquare(int);
void setTotalSquare(int);
};
//-----------------
void pointRow::makePointRowArray(int rowSize){
for (int i = 0; i < rowSize; i++){
pointRowArray[i] = new singlePoint;
}
}
void pointRow::setPointRowArray(int rowSize){
for (int i = 0; i < rowSize; i++){
pointRowArray[i]->xCoordinate = 11;
pointRowArray[i]->yCoordinate = 12;
}
}
void totalSquare::makeTotalSquare(int collumnSize){
for (int i = 0; i < collumnSize; i++){
totalSquareArray[i] = new pointRow;
}
}
void totalSquare::setTotalSquare(int collumnSize){
for (int collumnSet = 0; collumnSet < collumnSize; collumnSet++){
for (int rowSet = 0; rowSet < collumnSize; rowSet++){
// my problem lies somewhere in here
totalSquareArray[collumnSet]->pointRowArray[rowSet]->xCoordinate = 13;
totalSquareArray[collumnSet]->pointRowArray[rowSet]->yCoordinate = 14;
}
}
}
int main(void){
// this was just a test for pointRow and it’s fine
pointRow firstRow;
firstRow.makePointRowArray(size);
firstRow.setPointRowArray(size);
// this works up until…
totalSquare firstSquare;
firstSquare.makeTotalSquare(size);
// this point. I cannot assign 25
// I either get a bus error 10 or segmentation fault. what am I doing wrong?
firstSquare.totalSquareArray[0]->pointRowArray[0]->xCoordinate = 25;
return 0;
}
저는 왜 pointRow에서 작동하지만 현재는 totalSquare인지 알 수 없습니다.
생성자를 만들고 사용합니다. 정말 고마워. – 1N5818