所以现在我只是想设置一个简单的类,但无法弄清楚为什么我会出错。这是我的头文件:
#define Mob
class Mob{
private:
int lvl;
float hp;
public:
Mob(int, float); //Error expected an identifier on the float
};
和它的cpp文件
#include "Mob.h"
Mob::Mob(int level, float health) // Error expected an identifier on the int and float
// and an Error: Expected a ; after the )
{
hp = health;
lvl = level;
}
最佳答案
这一行:
#define Mob
导致单词 Mob
的每个实例在您的代码中被替换为任何内容。不要那样做。
看起来你想做一个 include guard ,它看起来应该是这样的:
#ifndef MOB_H
#define MOB_H
...
#endif
关于c++ - 错误 : Expected Identifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19323195/