错误:'*'标记之前的预期构造函数,析构函数或类型转换

Oli*_*noz 0 c++ singleton

我有一个C++类,我不断收到这个错误,虽然我有另一个用类似语法编写的类,可以毫不费力地编译.

这是我的.h:

#ifndef FISHPLAYER_H
#define FISHPLAYER_H

#include "Player.h"


class FishPlayer : public Player
{
public:
    float xThrust;
    float yThrust;
    static FishPlayer* getInstance();
protected:
private:
    FishPlayer();
    ~FishPlayer();
    static FishPlayer* instance;
};

#endif
Run Code Online (Sandbox Code Playgroud)

这是我的.cpp:

#include "..\include\FishPlayer.h"

FishPlayer* FishPlayer::instance=0;  // <== I Get The Error Here

FishPlayer::FishPlayer()
{
    //ctor
    xThrust = 15.0f;
    yThrust = 6.0f;
}

FishPlayer::~FishPlayer()
{
    //dtor
}


FishPlayer* FishPlayer::getInstance() { // <== I Get The Error Here
    if(!instance) {
        instance = new FishPlayer();
    }
    return instance;
}
Run Code Online (Sandbox Code Playgroud)

我一直在寻找一段时间,它一定是那么大我看不到的东西.

这是继承:

#ifndef PLAYER_H
#define PLAYER_H
#include "Ennemy.h"

class Player : public Ennemy
{
    public:
    protected:
        Player();
        ~Player();
    private:
};

#endif // PLAYER_H
Run Code Online (Sandbox Code Playgroud)

而较高的一个:

#ifndef ENNEMY_H
#define ENNEMY_H

#include "Doodad.h"

class Ennemy : public Doodad
{
    public:
        float speedX;
        float maxSpeedX;
        float speedY;
        float maxSpeedY;
        float accelerationX;
        float accelerationY;
        Ennemy();
        ~Ennemy();
    protected:
    private:
};
Run Code Online (Sandbox Code Playgroud)

和超类

#include <vector>
#include <string>


enum DoodadType{FishPlayer,Player,AstroPlayer,Ennemy,DoodadT = 999};
enum DoodadRange{Close, Medium , Far};
enum EvolutionStage{Tiny, Small, Average, Large};

class Doodad
{
    public:
        float score;
        void die();
        EvolutionStage evolutionStage;
        DoodadRange range;
        Doodad();
        virtual ~Doodad();
        Doodad(Doodad const& source);
        std::vector<Animation> animations;
        double posX;
        double posY;
        std::string name;
        std::string currentAnimation;
        int currentFrame;
        DoodadType type();
        SDL_Surface getSpriteSheet();
        bool moving;
        void update();
    protected:
    private:
        SDL_Surface spriteSheet;
};
Run Code Online (Sandbox Code Playgroud)

moh*_*aps 5

看起来你FishPlayer用作枚举值Doodad.h

它与您要声明的类名称相同.这可能是问题的根源.

通常,对枚举值使用FISH_PLAYERType_FishPlayer排序命名方案是个好主意,以避免像这样的冲突.