2

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;

}
4

2 に答える 2

2

循環依存が原因でしょうか?GameLabel には game.h.. が含まれており、ゲームも gamelabel に依存しているようですが、Game.h には gamelabel.h が含まれていますか?

于 2012-11-01T01:34:48.263 に答える
1

すべての .h ファイルの一番上に次のように記述します。

#ifndef YOUR_FILE_NAME_H_
#define YOUR_FILE_NAME_H_

そしてこれは一番下にあります:

#endif

YOUR_FILE_NAME_H_ を、使用している .h ファイル名に置き換えます。できれば大文字に置き換えてください。

これにより、ヘッダー ファイルが複数回インクルードされるのを防ぐことができます。

于 2012-11-01T01:46:22.890 に答える