问题描述
我有两个类:抽象的"Game"类和派生的"TestGame"类. TestGame中的所有功能都是单独实现的(为了使其能够编译).我只有一个错误:
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:
这是我的班级定义:
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 */ }
纯虚拟的= 0
是不必要的,因为您还有其他纯虚拟函数可以使您的类抽象化.
The = 0
for pure virtual is not necessary, since you have other pure virtual functions to make your class abstract.
这篇关于错误LNK2019-抽象类中的虚拟析构函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!