错误LNK2019无法解析的外部符号虚拟类 [英] error LNK2019 unresolved external symbol virtual class

查看:157
本文介绍了错误LNK2019无法解析的外部符号虚拟类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题已经问过几次了,但是我找不到解决方法.

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)

这是我的代码:

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.

推荐答案

该错误消息告诉您这是链接错误,因为您尚未实现~IGameState(), 尝试添加以下代码:

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

这篇关于错误LNK2019无法解析的外部符号虚拟类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆