error LNK2019 unresolved external symbol virtual class

不打扰是莪最后的温柔 提交于 2020-12-05 13:23:39

问题


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.


回答1:


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;
};


来源:https://stackoverflow.com/questions/17272385/error-lnk2019-unresolved-external-symbol-virtual-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!