简体   繁体   English

VS 2008的C ++编译错误

[英]VS 2008 compile error for C++

I have a couple of compile errors which are probably staring at me but I can't seem to resolve them. 我有几个编译错误,这些错误可能正在盯着我,但我似乎无法解决。 I've had a go at checking for solutions with the brackets, semi-colons and #includes but no joy. 我一直在用方括号,分号和#includes检查解决方案,但没有任何乐趣。 This is in VisualStudio 2008 with C++. 这是在Visual Studio 2008和C ++中。

The errors are; 错误是;

Error 1 error C2653: 'Game' : is not a class or namespace name logs.h 34 错误1错误C2653:“游戏”:不是类或名称空间名称logs.h 34

Error 2 error C3861: 'SetState': identifier not found logs.h 34 错误2错误C3861:'SetState':找不到标识符logs.h 34

Found here in logs.h 在logs.h中找到

Game::SetState(2);

Full header; 完整标头;

# pragma once

#include "DarkGDK.h"
#include "Screen.h"

class LogS:public Screen
{
    public:
        LogS():Screen()
        {

            //to be added
        }
        void SetBgrnd();
        void Skip();
};

void LogS::SetBgrnd()
{
    s_sprite_id = 1;
    dbShowSprite(11);
    Show();
}

void LogS::Skip()
{
    if(dbReturnKey())
    {
        dbHideAllSprites();
        Game::SetState(2);
    }
}

And the Game.h where it should using the static function from; 还有Game.h应该使用静态函数的地方;

# pragma once

#include "DarkGDK.h"
#include "LogS.h"

class Game
{
    static int gameState;

    public:
        Game();
        static void SetState(int gameState);

};

Game::Game()
{
    LoadImages();
    SetState(1);
}

inline void Game::SetState(gameState& g)
{
    gameState = g;
}

Edited out the non-relevant bits. 编辑掉无关的位。 If you can't tell, I'm new to this :P Any help is appreciated, thanks. 如果您不能告诉我,我是新手:P谢谢您的帮助。

static member variables must be defined outside class: 静态成员变量must在类外部定义:

class Game
{
   static int gameState;

public:
    Game();
    static void SetState(int gameState);

};
int Game::gameState = 0;

And as pointed out by @Drew Dormann: 正如@Drew Dormann所指出的:

Remove #include "LogS.h" from Game.h. 从Game.h中删除#include "LogS.h"

Game.h doesn't need the definition of LogS to compile. Game.h不需要LogS的定义即可进行编译。

Add #include "Game.h" to LogS.h. #include "Game.h"添加到LogS.h。

LogS.h needs the definition of Game to compile. LogS.h 需要 Game的定义才能进行编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM