C ++为什么我的课仍然很抽象? [英] C++ why is my class still abstract?

查看:82
本文介绍了C ++为什么我的课仍然很抽象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我肯定这很简单,但是我不知道为什么编译器认为我的一个类是抽象的。这种情况:

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 ++为什么我的课仍然很抽象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆