문제

I have the GameSettings class.

GameSettings.hpp

class GameSettings
{
public:
    GameSettings();

    GameSettings loadSettings();
    void saveSettings(GameSettings const & GS);

    sf::VideoMode getVideoMode() const {return VMode;}
    bool isFullscreen() const {return fullscreen;}

private:
    sf::VideoMode VMode;
    bool fullscreen;

};

One GameSettings is contained in Game class (Game class is Monostate):

Game.hpp

class Game
{
public:
    Game() {};

    static void init();
    static void run();
    static void clean();
private:
    static sf::Window window;
    static GameSettings currentGS;  
};

Here is the implementation of init function (only implemented function in Game class yet):

Game.cpp

void Game::init()
{
currentGS.loadSettings();
sf::Uint32 style = currentGS.isFullscreen() ? sf::Style::Fullscreen : sf::Style::None | sf::Style::Close;
window.create(currentGS.getVideoMode(), "Name", style);

}

And I'm getting these errors:

Game.hpp:

(twice) error C2146: syntax error : missing ';' before identifier 'currentGS' - Line 15

(twice) error C4430: missing type specifier - int assumed. Note: C++ does not support default-int - Line 15

Line 15: static GameSettings currentGS;

Game.cpp

error C2065: 'currentGS' : undeclared identifier - Lines 7, 8, 9

error C2228: left of '.loadSettings' must have class/struct/union - Line 7, 8, 9

These are only lines of init function ^

도움이 되었습니까?

해결책

Your code samples are incomplete. Are you including the headers for the classes you want to use? When you see an error like:

error C2065: 'currentGS' : undeclared identifier

or

error C2228: left of '.loadSettings' must have class/struct/union

It means that those variables or types (the identifier) are not known at this point in time -- and a common reason for that is you're not including a header file where the identifier is being declared. Make sure you're actually including the header files where you declare your variables and types.

다른 팁

You are putting const at wrong place

update:

void saveSettings(GameSettings & const GS);
                                 ^^^^^

to:

void saveSettings(GameSettings const & GS);
                               ^^^^^                 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top