SFML community forums

Help => Window => Topic started by: asdatapel on February 01, 2014, 02:39:17 am

Title: Window Initialization
Post by: asdatapel on February 01, 2014, 02:39:17 am
When I try to create a window object in Visual Studio C++, the line
sf::Window window = sf::Window(sf::VideoMode(200,200),"Title");
works fine, but when I try the same thing in Code::Blocks MinGW, I get a nonCopyable error. Instead I have to use
sf::Window window(sf::VideoMode(200, 200), "Title");
Any reason why?
Title: Re: Window Initialization
Post by: dabbertorres on February 01, 2014, 02:44:41 am
What version of Visual C++ and what version of MinGW?

Because technically, the first one is invalid. You're creating a sf::Window, and then copying it to "window".

Second one you're simply creating "window". Your second example is "more correct". As in you shouldn't want to be copying sf::Window.
Title: Re: Window Initialization
Post by: Azaral on February 01, 2014, 04:22:56 am
The first one shouldn't work at all because sf::Window inherits from sf::NonCopyable.

That is also why it doesn't work in Code::Blocks, because it shouldn't work.

http://www.sfml-dev.org/documentation/2.1/classsf_1_1Window.php
Title: Re: Window Initialization
Post by: thomas9459 on February 01, 2014, 05:06:16 am
I don't understand it too well, but Copy Elision (https://en.wikipedia.org/wiki/Copy_elision) could be the culprit, i.e. Visual Studio is treating the first code sample as if it were the second because the copy can be easily avoided.
Title: Re: Window Initialization
Post by: Nexus on February 01, 2014, 01:36:58 pm
C++ doesn't allow copy elision if the copy constructor is private (or deleted). The observable behavior must remain independent of optimizations.