编译错误:未声明的标识符

时间:2013-08-16 22:11:35

标签: c++ header compiler-errors

当我尝试编译程序时,我收到此错误,但我已经包含了包含'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

2 个答案:

答案 0 :(得分:0)

class Missile_mgr {

因此,Missile_mgr不是从任何类继承的。

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

LittleMonkey构造函数需要类型为Game*的参数。

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

在上面的陈述中,您试图将Missile_mgr *转换为Game *这是不可能的,编译器正在抱怨它。

答案 1 :(得分:0)

我花了两个小时才发现问题是:

class Missile_mgr {
public:

    enum MissileType { LittleMonkey, Calamar }; // <- LittleMonkey redefinition