error LNK2019 - Virtual destructor in abstract class [duplicate]

烈酒焚心 提交于 2019-12-30 11:16:09

问题


Possible Duplicate:
Pure virtual destructor in C++

I have two classes: the abstract "Game" class and the derived "TestGame" class. All of the functions in TestGame are implemented separately to nothing (for the sake of getting it to compile). I am only getting one error:

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)

Here are my class definitions:

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

I've tried a couple of things but I feel that maybe I am missing something fundamental about how abstracting and deriving classes works.


回答1:


You actually need to define the destructor for the base class even though it is pure virtual, since it will be called when the derived class is destroyed.

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

The = 0 for pure virtual is not necessary, since you have other pure virtual functions to make your class abstract.



来源:https://stackoverflow.com/questions/4380127/error-lnk2019-virtual-destructor-in-abstract-class

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