我作为最后的手段来到这里,因为我需要尽快帮助解决明天到期的任务。
我正在用 C++ 组合一个简单的引擎来处理节点、纹理/资产加载和状态系统。我想尝试继续编码与资产相关的东西,但为了做到这一点,我需要状态系统正常工作。
应用程序.h
#pragma once
#include "AppGSM\EGameStateManager.h"
class EGameStateManager;
class EApplication
{
public:
static void Init();
static void RunApp();
EGameStateManager* GetGameStateManager();
protected:
static int windowWidth;
static int windowHeight;
static bool fullScreen;
static bool frameSync;
static char* windowTitle;
};
目前,每当我尝试在我的 teststate 类和 main.cpp 中使用上面看到的指针指向游戏状态管理器时,我都会收到链接器错误。(见下文)
测试状态.cpp
#include "AppGSM\ETestState.h"
#include "AppGSM\EApplication.h"
#include <iostream>
ETestState::ETestState(EApplication* pApp){}
ETestState::~ETestState(){}
void ETestState::Update(float deltaTime)
{
//if(INPUT::GetKey(KEY_T))
//{
// cout << "Entered Test State" << endl;
//}
m_testTimer += deltaTime;
if(m_testTimer > 3.0f)
{
m_pApp->GetGameStateManager()->ChangeState("Second TEST");
}
}
void ETestState::Draw(){}
主文件
#include "GL\glew.h"
#include "GL\glfw.h"
#include <conio.h>
#include "AppGSM\EApplication.h"
#include "AppGSM\ETestState.h"
void main()
{
EApplication::Init();
EApplication* pApp = new EApplication();
pApp->GetGameStateManager()->SetState("TEST", new ETestState(pApp));
EApplication::RunApp();
}
这是包含在 teststate 中使用的应用程序指针的基本游戏状态类:
BASEGAMESTATE.h
#pragma once
class EApplication;
class EGameStateManager;
class EBaseGameState
{
public:
EBaseGameState(){}
EBaseGameState(EApplication* pApp);
//always make the destructor virtual !!
virtual ~EBaseGameState();
//all game states must define update and draw
virtual void Update(float deltaTime) = 0;
virtual void Draw() = 0;
protected:
EApplication* m_pApp;
};
这些是链接器错误:
Error 9 error LNK2019: unresolved external symbol "public: class EGameStateManager * __thiscall EApplication::GetGameStateManager(void)" (?GetGameStateManager@EApplication@@QAEPAVEGameStateManager@@XZ) referenced in function _main D:\Engine\main.obj
Error 10 error LNK2001: unresolved external symbol "public: class EGameStateManager * __thiscall EApplication::GetGameStateManager(void)" (?GetGameStateManager@EApplication@@QAEPAVEGameStateManager@@XZ) D:\Engine\ETestState.obj
通常我会将链接器错误归结为循环包含,但我已经写下了各种序列图,并且没有包含任何包含自身的东西。它可能很明显..我真的很紧张。任何帮助将非常感激。