4

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.

ApheX
  • 685
  • 2
  • 10
  • 26
  • 1
    You haven't defined it, only declared. That's enough for compiler, but not for linker. – jrok Jun 24 '13 at 09:42

1 Answers1

7

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;
};
billz
  • 44,644
  • 9
  • 83
  • 100