I can not add a single variable on a stack and draw it

1

I'm trying to make a program that makes a stack of objects using lib stack and then draw what's on top, to do some testing 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();

    }

So the way it is the code gives crash , but as soon as I create another object of type Tile and give push to the stack it works normally. Can anyone explain what might be happening?

The attributes of class Tile are all pointers that are initialized with new . I do not know if it helps, but I'm working with SFML.

I did a test and it worked. I created a new Tile b (initialized differently), and made a = b and gave push to a again and it worked. Can anyone explain?

    
asked by anonymous 21.11.2018 / 23:23

0 answers