c++ - 错误 LNK2019 - 抽象类中的虚拟析构函数

标签 c++ lnk2019 virtual-destructor

<分区>

Possible Duplicate:
Pure virtual destructor in C++

我有两个类:抽象的“Game”类和派生的“TestGame”类。 TestGame 中的所有函数都是单独实现的(为了使其能够编译)。我只收到一个错误:

TestGame.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall Game::~Game(void)" (??1Game@@UAE@XZ) referenced in function "public: virtual __thiscall TestGame::~TestGame(void)" (??1TestGame@@UAE@XZ)

这是我的类定义:

class Game
{
public:
    virtual ~Game(void) = 0;

    virtual bool Initialize() = 0;
    virtual bool LoadContent() = 0;
    virtual void Update() = 0;
    virtual void Draw() = 0;
};

class TestGame: public Game
{
public:
    TestGame(void);
    virtual ~TestGame(void);

    virtual bool Initialize();
    virtual bool LoadContent();
    virtual void Update();
    virtual void Draw();
};

我已经尝试了几件事,但我觉得我可能遗漏了一些关于抽象和派生类工作原理的基本知识。

最佳答案

您实际上需要为基类定义析构函数,即使它是纯虚拟的,因为它会在派生类被销毁时调用。

virtual ~Game() { /* Empty implementation */ }

纯虚的 = 0 不是必需的,因为您有其他纯虚函数来使您的类抽象。

关于c++ - 错误 LNK2019 - 抽象类中的虚拟析构函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4380127/

相关文章:

c++ - 可选的仅 header 库

c++ - 如何将 YUV 帧转换为视频?

c++ - 当我在网格/面中实现索引时,为什么会返回 OpenGl 错误?

c++ - 示例文件中的 CImg 图像加载错误

c++ - LNK2019/2001 : unresolved external symbol

c++ - VC++ 中 Unresolved external 错误

c++ - lnk2019 visual studio错误

c++ - "The Rule of Zero"是否也适用于具有虚方法的类?

c++ - 从析构函数体内部或外部调用叶类的成员函数有区别吗?

C++ 抽象类是否应该为(虚拟)析构函数提供实现?