【发布时间】:2011-10-03 08:21:57
【问题描述】:
你好,我已经在互联网上到处寻找答案,但我找不到任何答案。
代码:
#ifndef GAME_H
#define GAME_H
#include "drawEngine.h"
#include "sprite.h"
#include <iostream>
using namespace std;
class Game
{
public:
bool run(void);
protected:
bool getinput(char *c);
void timerUpdate(void);
private:
Sprite* player; // this gives me C2143
double frameCount;
double startTime;
double lastTime;
int posx;
//int posy;
DrawEngine drawArea;
};
#endif
我该如何解决这个问题?
精灵.h
#ifndef GAME_H
#define GAME_H
#include "drawEngine.h"
#include "game.h"
enum
{
SPRITE_CLASSID,
};
struct vector
{
float x;
float y;
};
class Sprite
{
public:
Sprite(DrawEngine *de, int s_index, float x = 1, float y = 1, int i_lives = 1);
~Sprite();
vector getPosition(void);
float getX(void);
float getY(void);
virtual void addLives(int num = 1);
int getLives(void);
bool isAlive(void);
virtual bool move(float x, float y);
protected:
DrawEngine *drawArea;
vector pos;
int spriteIndex;
int numLives;
int classID;
vector facingDirection;
void draw(float x, float y);
void erase(float x, float y);
private:
};
#endif
【问题讨论】:
-
我们可能需要看到`sprite.h"的内容才能对此进行智能评论。
-
可能是命名空间下的
Sprite类? -
该错误意味着
Sprite不是全局命名空间中的类名。Sprite没有在任何地方声明(也许您在sprite.h中有错字?),或者它在命名空间中声明,在这种情况下,您需要将其完全限定为TheNamespace::Sprite或添加using声明。 -
@Joachim Velzel:不要使用
using namespace std,尤其是在头文件中!