문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top