Generic User Generic User - 1 month ago 4
C++ Question

How do you return an sf::RenderWindow?

So I'm working on a tiny engine with my exploration into SFML. I currently am using a WindowManager class. Here is my code.

class WindowManager
sf::RenderWindow window;

void setWindow(int x, int y, std::string title)
window.create(sf::VideoMode(x, y, 32), title, sf::Style::Titlebar | sf::Style::Close);

sf::RenderWindow getWindow()
return window;
//Error Here


If you take a look at the inheritance diagram for sf::RenderWindow:

inheritance diagram

You'll notice that it inherits from sf::NonCopyable. So you can't return a copy of it... because its copy constructor and assignment operator are private.

What you can instead do is either return an sf::RenderWindow&, or an sf::RenderWindow*, or a std::shared_ptr<sf::RenderWindow>, or ...