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

ptp*_*son 2 c++ lnk2019 virtual-destructor

可能重复:
C++中的纯虚拟析构函数

我有两个类:抽象的"Game"类和派生的"TestGame"类.TestGame中的所有函数都是单独实现的(为了让它编译).我只收到一个错误:

TestGame.obj:错误LNK2019:未解析的外部符号"public:virtual __thiscall Game ::〜Game(void)"(?? 1Game @@ UAE @ XZ)在函数"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();
};
Run Code Online (Sandbox Code Playgroud)

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

Fre*_*son 10

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

virtual ~Game() { /* Empty implementation */ }
Run Code Online (Sandbox Code Playgroud)

= 0纯虚是没有必要的,因为你有其他纯虚函数,使您的抽象类.