SFML community forums
Help => Window => Topic started by: massive_potato on June 30, 2012, 03:41:57 am
-
What is the most efficient way to pass a RenderWindow to a function? Is one method preferable compared to another?
-
You can just pass a reference. (sf::RenderWindow &window); Passing by value won't have the desired result, and passing by pointer opens you up to unnecessary errors(like null values or dangling pointers). References provide the same advantages in this situation with no additional drawbacks.
Since RenderWindow inherits from RenderTarget, I prefer to pass a RenderTarget reference as it implements the same draw functions but could allow you to later change the target of the rendering system from the whole window to a RenderTexture or other object that derives from RenderTarget. I don't know if this usage is recommended, but I've had no problems with it so far.
-
I've been passing it that way, but I wasn't sure if there was a faster way to do it (my FPS has been a bit slow). Thanks for clearing things up!