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

Author Topic: Tutorial "Opening a window" code doesn't work righ  (Read 9829 times)

0 Members and 1 Guest are viewing this topic.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Tutorial "Opening a window" code doesn't work righ
« Reply #30 on: November 18, 2011, 07:36:56 am »
You're trying to copy a RenderWindow instance somewhere (this is probably implicit/hidden), which is not allowed.
Laurent Gomila - SFML developer

sbroadfoot90

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Tutorial "Opening a window" code doesn't work righ
« Reply #31 on: November 18, 2011, 08:46:41 am »
Probably this line here.

Code: [Select]
     states.back()->render(Window);

I'm guessing the signature for render is

Code: [Select]
void render(sf::RenderWindow Window);

or something like that. Change it to

Code: [Select]
void render(const sf::RenderWindow& Window);

Bacu

  • Newbie
  • *
  • Posts: 21
    • View Profile
Tutorial "Opening a window" code doesn't work righ
« Reply #32 on: November 18, 2011, 08:02:10 pm »
Quote from: "sbroadfoot90"
Probably this line here.

Code: [Select]
     states.back()->render(Window);

I'm guessing the signature for render is

Code: [Select]
void render(sf::RenderWindow Window);

or something like that. Change it to

Code: [Select]
void render(const sf::RenderWindow& Window);

winner winner. that was it.

sbroadfoot90

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Tutorial "Opening a window" code doesn't work righ
« Reply #33 on: November 18, 2011, 11:23:58 pm »
Actually, the methods you are likely to call on the RenderWindow in your render method are likely going to be Draw, and Display, both of which are not const methods. Thus, you should not pass a reference to const, but just a reference, as a reference to const will not allow you to call any methods that are not const-qualified.

Use

Code: [Select]
void render(sf::RenderWindow& Window);

basically any time you want to pass a non-integral type (not an int, float, etc) for example (std::vector, sf::RenderWindow, sf::Texture, etc), you should be passing by reference, not by copy. When you write

Code: [Select]
void someMethod(sf::Texture Texture);

you are copying ALL of the data that is held in the instance you are passing as a parameter, and you should opt to pass by reference


Code: [Select]
void someMethod(sf::Texture& Texture);

However, passing by reference allows you to change the original object that was passed in. To promise you wont change anything, you can pass a reference to const

Code: [Select]
void someMethod(const sf::Texture& Texture);

but then you are limited to using methods of sf::Texture that are const qualified for example

Code: [Select]
unsigned int GetWidth () const

however you would not be allowed to call

Code: [Select]
void Update (const Uint8 *pixels)

 

anything