繁体   English   中英

不完整类型不允许错误

[英]Incomplete type not allowed error

我创建了一个使用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;

}

可能是因为循环依赖? GameLabel包含game.h ..游戏似乎也依赖于游戏标签,Game.h是否包含gamelabel.h?

在你所有的.h文件中,在最顶层写下:

#ifndef YOUR_FILE_NAME_H_
#define YOUR_FILE_NAME_H_

而这在最底层:

#endif

将YOUR_FILE_NAME_H_替换为您所在的.h文件名,最好使用大写。

这将防止多次包含头文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM