简体   繁体   中英

Need help solving linker error in C++ engine/framework construction

I came here as a last resort as I need help with this asap for an assignment due tomorrow.

I'm putting together a simple engine in C++ that handles nodes, texture/asset loading and a state system. I'd like to try and move on to coding the asset related stuff but in order to do that I need the state system to be working.

APPLICATION.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;

};

Currently whenever I try and use the pointer seen above, in both my teststate class and my main.cpp, to the game state manager I receive linker errors. (seen below)

TEST STATE.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(){}

MAIN.cpp

#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();
}

and this is the base game state class that holds the application pointer used in 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;


};

these are the linker errors:

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

Usually I'd put linker errors down to cyclical includes but I've written down a sequence diagram of sorts and nothing includes anything that includes itself. Its probably something obvious.. I'm just really stressed. Any help would be much appreciated.

The linker can't find the function. You need to implement the GetGameStateManager() function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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