OK、これは私を困惑させています。比較的 C++ 初心者ですが、C# やその他の言語での長い経験があります。
問題のあるファイルを比較的簡単に要約すると、次のようになります。
/* GameObject.h */
#pragma once
#include <vector>
class GameObject {
public:
std::vector<Component *> *Components;
GameObject();
~GameObject();
};
/* GameObject.cpp */
#include "GameObject.h"
#include "Component.h"
GameObject::GameObject() {
}
GameObject::~GameObject() {
}
/* Component.h */
#pragma once
class Component {
public:
GameObject *Owner;
Component();
~Component();
};
/* Component.cpp */
#include "GameObject.h"
#include "Component.h"
Component::Component() {
}
Component::~Component() {
}
これにより、Visual C++ 2012 で 21 個のまったく無関係なエラーが生成されます。これは、コンポーネントをコンパイルできなかったという事実に起因していると思います。
C2065: 'Component' : undeclared identifier gameobject.h 10
C2059: syntax error : '>' gameobject.h 10
C2143: syntax error : missing ';' before '}' gameobject.h 14
C2143: syntax error : missing ';' before '{' component.h 3
C2143: syntax error : missing ';' before '}' component.h 11
C2143: syntax error : missing ';' before '{' gameobject.cpp 8
C2143: syntax error : missing ';' before '}' gameobject.cpp 9
C2143: syntax error : missing ';' before '{' gameobject.cpp 13
C2143: syntax error : missing ';' before '}' gameobject.cpp 14
C2143: syntax error : missing ';' before '}' gameobject.cpp 16
C1004: unexpected end-of-file found gameobject.cpp 16
C2065: 'Component' : undeclared identifier gameobject.h 10
C2059: syntax error : '>' gameobject.h 10
C2143: syntax error : missing ';' before '}' gameobject.h 14
C2143: syntax error : missing ';' before '{' component.h 3
C2143: syntax error : missing ';' before '}' component.h 11
C2653: 'Component' : is not a class or namespace name component.cpp 8
C2143: syntax error : missing ';' before '{' component.cpp 8
C2143: syntax error : missing ';' before '}' component.cpp 9
C2653: 'Component' : is not a class or namespace name component.cpp 13
C1903: unable to recover from previous error(s); stopping compilation component.cpp 13
何か案は?Component が GameObject へのポインターを持ち、GameObject が Components へのポインターのベクトルを持つことは設計上意味があるので、それを避けるために再構築するつもりはありません。ヘッダーファイルに何か問題があるだけだと思います。
アイデアをお寄せいただきありがとうございます。これは私を夢中にさせています。