EvilDuck
EvilDuck

Reputation: 63

How do I pass a sf::RenderWindow to another function?

Suppose I have a code in C++ SFML as follows;

void eventManager(sf::RenderWindow window)
{
    event evnt;
    window.pollEvent(evnt);
    if (evnt.type == sf::Event::Closed)
        window.close();
}

int main()
{
    sf::RenderWindow window(sf::VideoMode(500, 500), "Window");
    eventManager(window);
}

when I try to compile something like this, the debugger spits out an error message saying "attempting to reference a deleted function". I understand now that a sf::RenderWindow cannot be passed to another function, so what would be a better way to do this?

Upvotes: 1

Views: 1276

Answers (1)

EvilDuck
EvilDuck

Reputation: 63

Alter Igel told me how to do it in the comments, so I thought I'd post it as an answer so this can be closed (Thanks dude!)

I needed to declare the function like this;

 eventManager(sf::RenderWindow& window)

I assume the & lets the compiler know that it is referencing the window, not copying it. Again, credit to Alter Igel.

Upvotes: 3

Related Questions