I’m not able to add the same variable to a stack and draw it

Asked

Viewed 25 times

1

I’m trying to make a program that makes a stack of objects using lib stack and soon after draw whatever is on top, to do some tests I was doing the following:

int main() {

    RenderWindow wind(VideoMode(VideoMode::getDesktopMode().width, VideoMode::getDesktopMode().height), "titulo");

    Tile a = Tile(Vector2f(100,100), "txr_Wall.jpg", true);
    stack<Tile> f;
    f.push(a);
    a = Tile(Vector2f(100, 100), "txr_Grass.jpg", true);
    f.push(a);

    while (wind.isOpen()) {

        wind.clear(Color::Red);

        wind.draw(f.top().getSprite());

        wind.display();

    }

Just the way the code is crash, but as soon as I create another object like Tile and push to stack works normally. Can anyone explain to me what may be occurring?

The attributes of the class Tile are all pointers that are initialized with new. I don’t know if it helps, but I’m working with SFML.

I did a test and it worked. I created a new Tile b (different initialized), and did a = b and gave push in a again and it worked. Someone can explain?

  • 2

    Without knowing the definition of Tile, it is impossible to give any help.

  • As soon as possible I will put the definition.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.