-SFML- What do I put in referred to draw function to not get error?

Sprite classes initialize images to them and Player takes a reference to window:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

#include "Player.h"

Player::Player(sf::RenderWindow &_window): window(_window){

    //initialize all sprites belonging to players animation
    Sprites plLeft("template_left.png", 1, 6);


void Player::Draw(){


    window.draw(plLeft.sprite); //<---THIS WHAT DO I PUT IN HERE TO DRAW A SPRITE!
}



in main, I call the function to draw the sprite with pass by reference

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
                 ~~~~~


    sf::RenderWindow window(sf::VideoMode(800, 600), "BOMBER MAN");

    window.setFramerateLimit(30);

    Player pl(window);

    // run the program as long as the window is open
    while (window.isOpen()){

        //create an event object
        sf::Event event;

         //check for events
        while (window.pollEvent(event)){

          ~~~~
        }


        // clear the window with black colour
        window.clear(sf::Color::Black);

        //draw sprites
        pl.Draw();

        // end the current frame
        window.display();
    }


I want to know why i get this error:

~~error: '((Player*)this)->Player::plLeft' does not have class type|
Last edited on
I want to know why i get this error:

That's hard to say since you don't provide the relevant definition. The plLeft object in your constructor is local to the constructor and stops existing when the constructor returns. (Assuming it is actually in your constructor -- your code is incomplete and unclear.)
player .h is like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

class Player{
    public:

        Sprites plLeft(std::string, int ,int);
        Sprites plRight(std::string, int ,int);
        Sprites plUp(std::string, int ,int);
        Sprites plDown(std::string, int ,int);

        sf::RenderWindow &win;

        Player(sf::RenderWindow &_window);
        ~Player();


So, plLeft is a function which returns a Sprites object.

Your function doesn't have a data member sprite as your compiler was trying to tell you.
nono i seen this mistake so many times yet couldn't understand how it was..., plLeft isnt a function its an object of Sprites, Sprites owns lots of functions that return sprites of type sf::Sprite plus an initialised sprite object.

I can see I have to change some names to communicate better, sorry about that.

Also am trying to minimise the code I give you, used to have a bad habbit of giving people ev-ery-thang.
Last edited on
Sprites plLeft(std::string, int ,int);

This is a function declaration. It's declaring a method of the Player class, called plLeft.
This (std::string, int ,int) is a parameter list. Only functions have parameter lists.
So what else could it be good for?

I want to know why i get this error:
You did not provide the code for the error.
Topic archived. No new replies allowed.