小编Oli*_*noz的帖子

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

我有一个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 …
Run Code Online (Sandbox Code Playgroud)

c++ singleton

0
推荐指数
1
解决办法
1793
查看次数

标签 统计

c++ ×1

singleton ×1