Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Window Initialization  (Read 2933 times)

0 Members and 1 Guest are viewing this topic.

asdatapel

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Window Initialization
« 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?

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: Window Initialization
« Reply #1 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.

Azaral

  • Full Member
  • ***
  • Posts: 110
    • View Profile
Re: Window Initialization
« Reply #2 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

thomas9459

  • Newbie
  • *
  • Posts: 49
    • View Profile
    • Email
Re: Window Initialization
« Reply #3 on: February 01, 2014, 05:06:16 am »
I don't understand it too well, but 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.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Window Initialization
« Reply #4 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything