c++ - 错误 : Expected Identifier

标签 c++

所以现在我只是想设置一个简单的类,但无法弄清楚为什么我会出错。这是我的头文件:

#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/

相关文章:

c++ - 将值读入 C++ 的二维数组?

c++ - Eclipse CDT 无法解析 std:array,std::vector 工作正常

c++ - LibCurl CURLOPT_URL 不接受字符串? C++

c++ - 为什么 boost::numeric::interval::widen 的行为与手动应用相同的逻辑不同

c++ - 自定义迭代器

c++ - 子类调用意外的重载函数

C++ 模板中嵌套绑定(bind)的 C++ 错误 C2064

C++ 将文件读入数组/列表/vector

c++ - QObject::connect不起作用-用函数语法找不到信号

c++ - 在 boost::asio 中,为什么没有用于读/写的套接字成员函数?