c – 错误C2143:缺少’;’在’*’之前

你好我在互联网上到处寻找答案,但我找不到任何答案.

码:

#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

我该如何解决

sprite.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不被识别为类型.更好看后,你遇到的问题是你定义:
#ifndef GAME_H
#define GAME_H
//...
#endif

在两个文件中.你可以在.cpp文件(或Game.h文件……第一个代码片段)中执行此操作,也可以在Sprite.h文件中执行此操作.问题是,在编译器进入Sprite.h时,GAME_H已经定义,因此,由于#ifndef例程,它不再编译Sprite.h文件.

解决它在Sprite.h文件中的更改,如下所示:

#ifndef SPRITE_H
#define SPRITE_H
//...
#endif

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...