The code of Game.h:
#ifndef GAME_H
#define GAME_H
class Game
{
public:
const static string QUIT_GAME; // line 8
virtual void playGame() = 0;
};
#endif
The error:
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
What am I doing wrong?
Here is what you need to fix your issues:
1. Include the string header file:
#include <string>2. Prefix
stringwith its namespace:const static std::string QUIT_GAME;or insert a
usingstatement:3. Allocate space for the variable
Since you declared it as
staticwithin the class, it must be defined somewhere in the code:const std::string Game::QUIT_GAME;4. Initialize the variable with a value
Since you declared the string with
const, you will need to initialize it to a value (or it will remain a constant empty string).:const std::string Game::QUIT_GAME = "Do you want to quit?\n";