C++ why is my class still abstract?

2019-02-23 02:59发布

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

And I inherit from it as so:

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

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)
{
}

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

Thanks

1条回答
Anthone
2楼-- · 2019-02-23 03:43

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.

查看更多
登录 后发表回答