可能重复:
错误:“{”标记之前的预期类名
我有一个主要的超类 GameObject 和派生类 GuiBitMapFont。它总是抛出预期的类名错误。但是如果我在 GuiBitMapFont类 GameObject 中添加前向推导;它会引发对不完整类型 'class GameObject' 的无效使用和 'class GameObject' 的前向声明。
编辑 是的,GameObject 文件中有#include GuiBitMapFont。但这是我在写这个问题时的错误。编译器仍然抛出这两个错误。
#ifndef GAMEOBJECT_H
#define GAMEOBJECT_H
#include <string>
#include "Texture.h"
class GameObject {
private:
int x;
int y;
int width;
int height;
public:
GameObject();
GameObject(int x, int y, int width, int height);
GameObject(const GameObject& orig);
virtual ~GameObject();
virtual void draw();
virtual void update();
//ignore those, i need to rewrite it....
void setX(int x);
void setY(int y);
void setWidth(int width);
void setHeight(int height);
int getX() const;
int getY() const;
int getWidth() const;
int getHeight() const;
};
#endif /* GAMEOBJECT_H */
并派生出
#ifndef GUIBITMAPTEXT_H
#define GUIBITMAPTEXT_H
#include <string>
#include "SDL.h"
#include "GameObject.h"
#include "BMF.h"
class GuiBitMapText : public GameObject { //error: expected class-name before '{' token
private:
std::string text;
BMF *font;
//SDL_Surface *surf;
SDL_Texture *texture;
public:
GuiBitMapText(int x, int y, std::string text, BMF *font);
GuiBitMapText(const GuiBitMapText& orig);
virtual ~GuiBitMapText();
virtual void draw();
virtual void update();
};
#endif /* GUIBITMAPTEXT_H */