我创建了一个使用openGL显示标签(GameLabel)的类,但遇到了2个非常奇怪的错误,我无法解决。
错误C2079:“displayPlayer”使用未定义的类“GameLabel”
IntelliSense:不允许输入不完整的类型
这是我的代码;
Game.cpp中调用标签类的函数
void Game::draw(SDL_Window *window)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear window
// draw player
glColor3f(1.0,1.0,1.0);
glBegin(GL_POLYGON);
glVertex3f (xpos, ypos, 0.0); // first corner
glVertex3f (xpos+xsize, ypos, 0.0); // second corner
glVertex3f (xpos+xsize, ypos+ysize, 0.0); // third corner
glVertex3f (xpos, ypos+ysize, 0.0); // fourth corner
glEnd();
GameLabel displayPlayer = new GameLabel(xpos+(xsize/2.0f), ypos+ysize, "Player");
//The ablove line is the one flagging the errors.
现在是GameLabel.h。
#include <SDL_ttf.h>
#include <GL/glew.h>
#include <string>
#include "Game.h"
class GameLabel
{
public:
GameLabel(float fx, float fy, char stri);
~GameLabel(void);
void textToTexture(const char * str, SDL_Surface* stringImage);
void draw(SDL_Surface* stringImage);
friend class Game;
protected:
SDL_Surface stringImage;
private:
GLuint texID;
GLuint height;
GLuint width;
GLfloat x;
GLfloat y;
char str;
};
最后是GameLabel.cpp构造函数
GameLabel::GameLabel(float fx, float fy, char stri)
{
x = fx;
y = fy;
str = stri;
}
最佳答案
可能是由于循环依赖吗? Game Label包含game.h ..并且游戏似乎也取决于gamelabel,Game.h是否包含gamelabel.h?
关于c++ - 类型不完整,不允许出现错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13169785/