C+#包括警衛(wèi)我是C+新手,但我在C#和Java方面有一些編程經驗,所以我可能缺少一些C+特有的基本知識。問題是我不知道出了什么問題,我會粘貼一些代碼來解釋這個問題。我有三門課,GameEvents,物理學和GameObject。我有他們每一個的標題。GameEvents有一個物理和一個游戲對象列表。物理學有一個游戲對象列表。我想要實現(xiàn)的是,我希望GameObject能夠訪問或擁有一個物理對象。如果我簡單地將“Physics.h”包含在GameObject中,我就會得到我理解的“錯誤C 2111:‘ClassXXX’:‘class’type refinition”。這就是我認為#包括-后衛(wèi)會有幫助的地方,所以我給我的物理防護增加了一個包括后衛(wèi)。h,因為這是我想要包括兩次的標題。這就是它的樣子#ifndef PHYSICS_H#define PHYSICS_H#include "GameObject.h"#include <list>class Physics{private:
double gravity;
list<GameObject*> objects;
list<GameObject*>::iterator i;public:
Physics(void);
void ApplyPhysics(GameObject*);
void UpdatePhysics(int);
bool RectangleIntersect(SDL_Rect, SDL_Rect);
Vector2X CheckCollisions(Vector2X, GameObject*);};#endif // PHYSICS_H但是,如果我在我的GameObject.h中包含“Physics.h”,現(xiàn)在如下所示:#include "Texture2D.h"#include "Vector2X.h"#include <SDL.h>#include "Physics.h"class GameObject{private:
SDL_Rect collisionBox;public:
Texture2D texture;
Vector2X position;
double gravityForce;
int weight;
bool isOnGround;
GameObject(void);
GameObject(Texture2D, Vector2X, int);
void UpdateObject(int);
void Draw(SDL_Surface*);
void SetPosition(Vector2X);
SDL_Rect GetCollisionBox();};我有很多問題不明白他們?yōu)槭裁磿霈F(xiàn)。如果我不包括“Physics.h”,我的代碼運行得很好。我非常感謝你的幫助。
3 回答

慕森卡
TA貢獻1806條經驗 獲得超8個贊
Physics.h
GameObject.h
Physics.h
Physics
GameObject*
GameObject.h
Physics.h
#include "GameObject.h"
class GameObject;
- 3 回答
- 0 關注
- 378 瀏覽
添加回答
舉報
0/150
提交
取消