问题描述
我确信这对我来说很简单,但我不明白为什么我的编译器认为我的一个类是抽象的.情况如下:
I'm sure its something simple on my part, but I can't figure out why my compiler thinks one of my classes is abstract. Here's the situation:
我有一个像这样的抽象基类:
I have an abstract base class like so:
class AnimatedDraw
{
public:
virtual void Draw(sf::RenderWindow &window) = 0;
virtual void Draw(sf::RenderWindow &window, sf::Shader shader) = 0;
virtual void Update(sf::Clock &time) = 0;
};
我继承了它:
class ScreenLayer : public AnimatedDraw
{
public:
ScreenLayer(void);
virtual void Draw(sf::RenderWindow &window);
virtual void Draw(sf::RenderWindow &window, sf::Shader &shader);
virtual void Update(sf::Clock &clock);
~ScreenLayer(void);
};
供参考,ScreenLayer.cpp文件如下:
for reference, the ScreenLayer.cpp file is as follows:
#include "ScreenLayer.h"
ScreenLayer::ScreenLayer(void)
{
}
void ScreenLayer::Draw(sf::RenderWindow &window)
{
}
void ScreenLayer::Draw(sf::RenderWindow &window, sf::Shader &shader)
{
}
void ScreenLayer::Update(sf::Clock &clock)
{
}
ScreenLayer::~ScreenLayer(void)
{
}
然而,当我尝试使用我的派生类(即 AnimatedDraw *testDrawer = new ScreenLayer;
)时,我的编译器抱怨 ScreenLayer 是抽象的.出于同样的原因,将 AnimatedDraw 更改为 ScreenLayer 也是无效的.我覆盖了基类上的所有抽象函数,不是吗?我不确定为什么它被视为抽象的.任何帮助将不胜感激
However, when I try to use my derived class (i.e. AnimatedDraw *testDrawer = new ScreenLayer;
) my compiler complains the ScreenLayer is abstract. Changing AnimatedDraw to ScreenLayer was also invalid for the same reason. I overwrote all the abstract function on my base class didn't I? I'm not sure why it's being seen as abstract. Any help would be appreciated
谢谢
推荐答案
你的基类声明在 sf::Shader 之后没有 & 符号:
Your base class declaration doesn't have an ampersand after sf::Shader:
virtual void Draw(sf::RenderWindow &window, sf::Shader shader) = 0;
派生类有,因此它是一个不同的重载函数.
The derived class has, hence it's a different overloaded function.
这篇关于C++ 为什么我的类仍然是抽象的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!