Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ why is my class still abstract?

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

like image 926
Megatron Avatar asked Mar 24 '11 07:03

Megatron


1 Answers

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.

like image 100
sashoalm Avatar answered Oct 05 '22 12:10

sashoalm