다른 클래스를 사용하는 액세스 방법과 매개 변수에 문제가 있습니다. Java로 코딩 했으므로 다른 범위의 함수를 사용하는 데 문제가 없습니다.C++에서 다른 클래스의 데이터 가져 오기
class Ball;
class Canvas4 {
public:
static const int num = 100;
vector<Ball> ballCollection;
Ball *myBall;
Ball getBallById(int id) {
return this->ballCollection.at(id)
};
};
class Ball {
friend class Canvas4;
public:
void lineBetween() {
for (int i=0; i<Canvas4::num; i++) {
Ball other = Canvas4::ballCollection.at(i);
//*Invalid use of non-static data member "ballCollection"
}
};
};
* 비 정적 데이터 멤버 "ballCollection"나는 ID로 특정 볼 개체의 내용을 읽고 몇 가지 예술을 그리려는
의 사용이 잘못되었습니다.
내가 한 다른 클래스에 편집
.
#include "canvas4.h" //which contains both classes Ball and Canvas4
Canvas4 canvas4;
, 당신은 Canvas4''클래스의 인스턴스를 필요 그 비 정적 멤버들. –
Canvas4 canvas4를 설치합니다. 메인 클래스. – cleliodpaula
그래서 그 인스턴스에 대한 참조를'lineBetween' 또는이 라인을 따라 무엇인가에 대한 매개 변수로 전달하십시오. 프로그램에 여러 캔버스가있을 수 있습니다. 'lineBetween'이 볼 컬렉션을 알아야한다고 생각 하는게 또 뭐죠? –