cannot declare variable ‘sasuke’ to be of abstract type ‘Character’

Viewed 30

I am learning to use the SFML library, I am following a course on youtube and I can't get it to compile this part of the program.

class Character: public sf::Drawable{
  
  public:
  
  sf::Sprite _sprite;
  sf::Texture _texture;
  float _velocity = 6;
  
  void draw(sf::RenderTarget& target, sf::RenderStates states) const override{
    target.draw(_sprite, states);
  }

Instantiating the object in main.cpp

#include <SFML/Graphics.hpp>
#include "character.h"

int main()
{   
sf::RenderWindow window(sf::VideoMode({1343, 715}), "SFML");

window.setFramerateLimit(60);
Character sasuke;

while (window.isOpen())
{
    sf::Event event;
    while (window.pollEvent(event))
    {
        if (event.type == sf::Event::Closed)
            window.close();
    }

    sasuke.update(); 
    window.clear();
    window.draw(sasuke);
    window.display();
}

return 0;
}

Error and a note:

main.cpp: In function ‘int main()’:
main.cpp:9:15: error: cannot declare variable ‘sasuke’ to be of abstract type ‘Character’
    9 |     Character sasuke;
      |               ^~~~~~
character.h:3:7: note:   because the following virtual functions are pure within ‘Character’:
    3 | class Character: public sf::Drawable{
1 Answers

Your const is misplaced

void draw(sf::RenderTarget& target, sf::RenderStates states) const override{

It's the draw method that should be declared const, not the states parameter.

Related