我創建了一個類,它使用openGL顯示標籤(GameLabel),我得到了2個非常奇怪的錯誤,我無法解決。不完整類型不允許錯誤
錯誤C2079: 'displayPlayer' 使用未定義類GameLabel' 智能感知:不完全類型是不允許
這裏是我的代碼;
在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;
}
愚蠢的問題..但你確實包括.h對嗎?這些編譯錯誤還是隻是intellisense錯誤? –
我不是這是你的核心問題,而是'GameLabel displayPlayer = new GameLabel(...);'似乎對我而言。你忘了'*'來聲明'displayPlayer'作爲一個指針(例如'GameLabel * displayPlayer = new ...')? –
另一個問題是,在你的GameLabel構造函數中,第三個參數是一個char,但是試圖使用一個字符串。 – imreal