错误:令牌之前的预期构造函数、析构函数或类型转换'*'
error: expected constructor, destructor, or type conversion before '*' token
我有一个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
这是我的.cpp:
#include "..includeFishPlayer.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;
}
我已经找了一段时间了,它一定是这么大的东西,我看不到它。
这是继承:
#ifndef PLAYER_H
#define PLAYER_H
#include "Ennemy.h"
class Player : public Ennemy
{
public:
protected:
Player();
~Player();
private:
};
#endif // PLAYER_H
而更高的一个:
#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:
};
和超阶级
#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;
};
看起来您在Doodad.h
中使用FishPlayer
作为枚举值
它与您尝试声明的类同名。这可能是问题的根源。
一般来说,最好使用FISH_PLAYER
,或者Type_FishPlayer
枚举值的命名方案,以避免这样的冲突。
相关文章:
- LINUX 操作系统上的错误:令牌之前预期的构造函数、析构函数或类型转换'('?
- 错误 c++ 在令牌之前'('预期的构造函数、析构函数或类型转换
- 错误:在“(”标记之前进行预期的构造函数、析构函数或类型转换.即使我有一个构造函数
- 获取错误:在“(”标记之前进行预期的构造函数、析构函数或类型转换
- 如何销毁通过"放置新"构造的无析构函数类型
- 错误:令牌之前的预期构造函数、析构函数或类型转换'*'
- 不同的析构函数类型
- 字符串常量之前的预期构造函数、析构函数或类型转换
- 需要构造函数/析构函数/类型转换错误
- C++模板错误:'<'令牌之前的预期构造函数、析构函数或类型转换
- 错误:在非常简单的示例中,预期的构造函数、析构函数或类型转换
- 错误:'<'令牌之前的预期构造函数、析构函数、类型转换
- 令牌之前的预期构造函数、析构函数或类型转换'*'
- 错误:标记之前的预期构造函数、析构函数或类型转换?
- 错误:在“(”标记之前进行预期的构造函数、析构函数或类型转换
- C++ 错误:令牌之前的预期构造函数、析构函数或类型转换'*'
- C++ 错误:在“(”标记之前进行预期的构造函数、析构函数或类型转换
- 预期的构造函数、析构函数或类型转换
- 不稳定的声明行为:Rational.h:25:错误:在"&"标记之前预期的构造函数、析构函数或类型转换
- 编译时错误:期望的构造函数、析构函数或转换