-1

当我尝试编译我的程序时,我在下面收到此错误,但我已经包含了包含“LittleMonkey”类声明的头文件。

1>------ Build started: Project: Estrellas, Configuration: Debug x64 ------
1>Build started 17/08/2013 0:24:31.
1>InitializeBuildStatus:
1>  Touching "x64\Debug\Estrellas.unsuccessfulbuild".
1>ClCompile:
1>  Missile_mgr.cpp
1>Missile_mgr.cpp(68): error C2146: syntax error : missing ';' before identifier 'monkey'
1>Missile_mgr.cpp(68): error C3861: 'monkey': identifier not found
1>Missile_mgr.cpp(79): warning C4482: nonstandard extension used: enum 'MissileEventType' used in qualified name
1>Missile_mgr.cpp(99): warning C4482: nonstandard extension used: enum 'MissileEventType' used in qualified name
1>Missile_mgr.cpp(106): warning C4482: nonstandard extension used: enum 'MissileEventType' used in qualified name
1>Missile_mgr.cpp(113): warning C4482: nonstandard extension used: enum 'MissileEventType' used in qualified name
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:03.21
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我对这两个文件做错了吗?

Missile_mgr.cpp:

#include "Missile_mgr.h"
#include "Constants.h"
#include "Game.h"
#include "Missile.h"

void Missile_mgr::Test() {

    LittleMonkey monkey(pGame); 

}

Missile.h,其中包含 LittleMonkey

#ifndef MISSILE_H
#define MISSILE_H

#include "Object.h"
#include "AnimatedSprite.h"

class Game;

class Missile : public Object {
public:
    AnimatedSprite aSp;
    Missile(Game* _pGame);
    virtual void Load()=0;
    virtual void Update()=0; 
    void Draw();

    Game* pGame;
};


class LittleMonkey : public Missile {
public:
    explicit LittleMonkey(Game* _pGame) : Missile(_pGame) { };
    virtual void Load();
    virtual void Update();

};

#endif

Missile_mgr.h

#ifndef MISSILE_MGR_H
#define MISSILE_MGR_H

#include "Quadtree.h"
#include "Missile.h"

class Game;

enum MissileEventType { Wave, WaitForClean, WaitTime, Boss };

struct MissileEvent {
    MissileEventType eventType;
    union {
        int WaitTime;
    } aditional;
};

class Missile_mgr {
public:
    enum MissileType { LittleMonkey, Calamar  };

    bool initialize(Game* _pGame);
    void LoadLevel(int level);
    void Update(); // Update() calls HandleEvents()
    void Draw();
    void Clear();

    std::list<Missile*> missileList;
    sf::Texture txLittleMonkey;
    sf::Texture txBigMonkey;
    sf::Texture txCalamar;
    sf::Texture txFruits;
    sf::Texture txRockets;
    sf::Texture txStars;
    // Do waves?

    float wait;// this is for wait event.
    bool waiting;

    Game* pGame;
private:
    bool HandleEvents();
    void DoWave();
    void DoBoss();
    std::vector<MissileEvent> eventQueue;
    void AddMissile(MissileType* type);

};

#endif
4

2 回答 2

0

我花了两个小时才弄清楚问题是:

class Missile_mgr {
public:

    enum MissileType { LittleMonkey, Calamar }; // <- LittleMonkey redefinition
于 2013-08-17T00:09:27.500 回答
0
class Missile_mgr {

所以,Missile_mgr不是从任何类继承的。

explicit LittleMonkey(Game* _pGame) : Missile(_pGame) { }

但是LittleMonkey构造函数需要一个 type 的参数Game*

void Missile_mgr::Test()
{
   LittleMonkey monkey(this);

在上面的声明中,你试图强制Missile_mgr *转换Game *为不可能的,编译器抱怨它。

于 2013-08-16T22:36:23.540 回答