다음 클래스 구조가 있습니다. 이것은 분명히 컴파일되지 않습니다. 나는 B를 선언 할 수있다. 그렇다면 함수 호출에서 함수 포인터를 사용할 수도 있지만 좋은 해결책은 아니다. A에서 funcA에서 다른 함수를 호출하거나 B의 선언 부분을 헤더에 넣으면된다. 이것은 몇 백 줄의 것이 어 실용적이다.C++ 03 멤버 함수를 호출 할 때 원 구성을 확인하십시오.
이 상황을 처리하기 위해 선호되는 방법은 무엇입니까?
아
Class B;
Class A {
declaration of A
};
A.cpp ....
BH
:class B;
class A
{
public:
void funcA(B* b);
double funcA2();
int funcA4(B* b);
private:
E memberA1;
E memberA2;
};
void A::funcA(B* b) {
b->funcB(a->memberA1, a->memberA2);
class B : public BBase
{
public:
void FuncB(E* e1, E* e2)
{
/* using const objects of B that are initialized
by B() and some other functions... */
}
std::vector<C*> memberB1; // C has std::vector<A*> memberC1
};
int main() {
calling B->memberB1.at(0)->memberC1.at(0)->funcA();
}
나는 다음 (생략 일부 unneccesary 라인)가 ,
#include "A.h"
#include "BBase.h"
Class B {
declaration of B
};
B.cpp ....
BBase.h
#include "C.h"
#include "A.h"
#include "AInterface.h"
typedef std::vector<AInterface> AList;
BBase {
declaration of abstract BBase
};
BBase.cpp ....`
하지만 여전히 오류가 발생합니다 : 불완전한 유형 'B'에 대한 회원 액세스.
"BBase.cpp"에''B.h "'가 포함되어 있습니까? –
아니요,'cpp'-s에는 오직 대응하는'.h' 만 포함되어 있습니다. 예 : 'BBase.cpp'는'BBase.h' 만 가지고 있습니다. – CreMinES
* 어디에서 * 오류가 있습니까? 'B'를 사용한다면'B' 클래스의 완전한 정의가 필요하므로'B.h' 파일을 그 소스 파일에 포함시켜야합니다. –