【发布时间】:2014-04-04 19:12:35
【问题描述】:
我在 openGl 中创建一个游戏,我遇到了一个困扰我近 2 小时的问题。 主要功能在包含 World.h 的 readobj.cpp 中,我有一个使用 Ball.h 和 Stick.h 的 World.h 文件。另一方面,Ball.h 和 Stick.h 都在使用 Game.h 文件。
世界.h
#include "Ball.h"
#include "Camera.h"
#include "Stick.h"
class World
{
Ball ball[15];
Ball qBall;
Camera camera;
public:
World();
void update();
void render();
};
Stick.h
#include "Game.h"
class Stick
{
point power;
public:
void setPosition(point);
void setPower(point);
void render();
void update();
};
球.h
#include "Game.h"
class Camera
{
public:
Camera();
void update();
void render();
};
游戏.h
class point {
public:
double x,y,z;
};
我得到的错误是
g++ -Wall -c readobj.cpp -L. -lBall -lWorld -lCamera -lStick
In file included from Camera.h:1:0, from World.h:2, from readobj.cpp:12:
Game.h:1:7: error: redefinition of ‘class point’
Game.h:1:7: error: previous definition of ‘class point’
In file included from Stick.h:1:0,
from World.h:3,
from readobj.cpp:12:
Game.h:1:7: error: redefinition of ‘class point’
Game.h:1:7: error: previous definition of ‘class point’
【问题讨论】:
-
您遇到什么错误?您似乎没有保护您的标头不被多次包含。
标签: c++ opengl header-files