gpt4 book ai didi

c++ [gamestate]函数不接受正确的参数错误

转载 作者:行者123 更新时间:2023-11-28 04:28:37 25 4
gpt4 key购买 nike

你好,我的代码编译有问题

我关注 http://gamedevgeek.com/tutorials/managing-game-states-in-c/教程但它无法编译,我不知道为什么。

来自 visual studio 的错误信息 enter image description here

这是我的代码

CGameEngine修改代码

    #include <vector>
#include "GameState.h"
#include "GameEngine.h"

class GameState;

class GameStateManager
{
public:
GameStateManager(GameEngine* engine, MSG * msg);
~GameStateManager();

void Cleanup();
void ChangeState(GameState* state);
void Update();
bool Running() { return m_running; }
void Quit();

private:
std::vector<GameState *> states;
bool m_running;
GameEngine * m_engine;
MSG *m_msg;
};

#include "GameStateManager.h"


GameStateManager::GameStateManager(GameEngine* engine, MSG * msg)
:m_engine{ engine }, m_msg{ msg }, m_running{ true }
{

}

GameStateManager::~GameStateManager()
{

}

void GameStateManager::Cleanup()
{
while (!states.empty()) {
states.back()->Exit();
states.pop_back();
}
}

void GameStateManager::Quit()
{
m_running = false;
m_msg->message = WM_QUIT;
}

void GameStateManager::ChangeState(GameState* state)
{
if (!states.empty()) {
states.back()->Exit();
states.pop_back();
}

states.push_back(state);
states.back()->Enter(m_engine, m_msg);
}

void GameStateManager::Update()
{
states.back()->Update(this);
}

CGameState修改代码

    #include "GameStateManager.h"

class GameState
{
public:
GameState() {}
virtual ~GameState() {}
virtual void Enter(GameEngine * , MSG * ) = 0;
virtual void Update(GameStateManager* game) =0;
virtual void Exit() = 0;

};

国家级之一

#include "MainMenu.h"

class Logo :public GameState
{
public:
Logo();
~Logo();

static Logo* Instance()
{
return &m_Logo;
}

void Enter(GameEngine * engine, MSG * msg);
void Update(GameStateManager* game);
void Exit();
private:

static Logo m_Logo;

};

#include "Logo.h"

Logo::Logo()
{

}

Logo::~Logo()
{

}
void Logo::Enter(GameEngine * engine, MSG * msg)
{
m_GameEngine_Info = engine;
m_msg = msg;

}

void Logo::Update(GameStateManager* game)
{


}

void Logo::Exit()
{


}

我在编辑代码时没有遇到编译错误,但是当我尝试编译时出现此错误。

最佳答案

您有循环包含。使用包括守卫和替换

#include "GameStateManager.h"

class GameStateManager;

在 GameState.h 中。将此包含移动到 GameState.cpp 中。

在 GameStateManager.h 和 GameStateManager.cpp 中使用 #include "GameEngine.h"#include "GameState.h" 做类似的事情。

关于c++ [gamestate]函数不接受正确的参数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53616894/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com