Search code examples
c++visual-studio-2010inheritancevirtualabstract-class

error LNK2019 unresolved external symbol virtual class


I know this question was asked several time, but i don't find how to resolve it.

I get this error when i'm trying to build my project:

error LNK2019: unresolved external symbol "public: virtual __thiscall IGameState::~IGameState(void)" (??1IGameState@@UAE@XZ) in function "public: virtual __thiscall MenuState::~MenuState(void)" (??1MenuState@@UAE@XZ)

Here is my code:

IGameState.h

class IGameState
{
    public:
        virtual ~IGameState();
        virtual void update() = 0;
        virtual void render() = 0;
};

MenuState.h

#include "IGameState.h"

class MenuState : public IGameState
{
public:
    MenuState();
    ~MenuState();
    void update();
    void render();
};

MenuState.cpp

#include "MenuState.h"

#pragma region Constructor

MenuState::MenuState() {

}

MenuState::~MenuState() {

}

#pragma endregion


void MenuState::render() {

}

void MenuState::update() {

}

What's wrong with the destructor? Thanks.


Solution

  • The error message tells you that's a link error, because you haven't implemented ~IGameState(), Try add below code:

    class IGameState
    {
        public:
            virtual ~IGameState() {} 
                                //^^^^ define it
            virtual void update() = 0;
            virtual void render() = 0;
    };