c++ - 视觉 C++ : Compiler Error C4430

标签 c++ visual-c++ syntax-error

Game.h代码:

#ifndef GAME_H
#define GAME_H

class Game
{
    public:
        const static string QUIT_GAME; // line 8
        virtual void playGame() = 0;
};

#endif

错误:

game.h(8): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
game.h(8): error C2146: syntax error : missing ';' before identifier 'QUIT_GAME'
game.h(8): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

我做错了什么?

最佳答案

你需要做两件事:

  • #include <string>
  • 将类型更改为 const static std::string QUIT_GAME (添加 std:: )

关于c++ - 视觉 C++ : Compiler Error C4430,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2916691/

相关文章:

c++ - 如果我们有一个包含所有代码的单个文件项目,我们可以不使用链接器吗?

c++ - 在 C++ 中包含文件错误

c++ - 有一个静态库,有没有一种简单的方法可以知道它是 32 位还是 64 位?

visual-c++ - Visual C++不会同时显示两个重新定义错误

c++ - 通过选择功能读取控制台输入

sql - DB2中的错误(CARDINALITY)

c++ - 避免窗口标题

c++ - 如何获取关键点 "within the homography"?

sql - 使用余数在ms Access 中设置字段值

php - 使用 xargs 在整个目录中验证 PHP 语法