2 차원 포인터 클래스 배열을 만들려고합니다. 클래스 개체 그리드가 필요합니다. 지금 말한 오류가 발생합니다 :C++ 2 차원 포인터 클래스 배열 오류 (openframeworks 사용)
testApp.cpp | 53 | error : '((testApp *) this) -> testApp :: myCell [i] '|
// this is cell.h
class Cell
{
public:
int x;
};
.
// this is testApp.h
class testApp : public ofBaseApp{
public:
int width;
int height;
int Grid;
int space;
float wWidth;
float wHeight;
Cell myCell;
void setup();
void update();
void draw();
};
'.' 는 이것은 testapp.cpp 이다 // // 오류가 myCell 포인터와 x 매개 변수를 adressing에 문제가 왜 이해가 안
void testApp::setup(){
Cell *myCell[5][5];
myCell[1][0]->x =2;
myCell[2][0]->x =1;
myCell[3][0]->x =23;
myCell[4][0]->x =4;
myCell[5][0]->x =7;
myCell[0][0]->x =4;
}
//--------------------------------------------------------------
void testApp::draw(){
ofSetColor(255,255,0);
for (int i = 0; i<5; i++) {
int q = myCell[i][0]->x; // i get the error here.
ofCircle(20*q,20*q,50);
}
}
곳이 있습니다.
도움을 주시면 대단히 감사하겠습니다.
을 직접'myCell'에 대한'int'를 사용하여'만'INT를 노출 Cell'을 사용 x' 공개적으로 대신 할 특별한 이유가 다음과 같이 이제 배열의 내용을 설정할 수 있습니다 ? – Nobody
setup의 myCell 배열이 초기화되지 않았습니다. 즉,이 배열의 포인터가 유효하지 않고 참조를 해제하면 정의되지 않은 동작이 발생합니다. – Nobody
지금'int x'는 테스트입니다. 나중에 나는'myCell'의 여러 변수에 기초하여 다양한 모양을 그릴 필요가있다. – Bluefarmer