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

Author Topic: cannot pass RenderWindow object by const reference  (Read 2097 times)

0 Members and 1 Guest are viewing this topic.

iride

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
    • Email
cannot pass RenderWindow object by const reference
« on: September 05, 2012, 04:29:03 am »
I have a game object that receives reference to RenderWindow object
And this game.draw passes the const reference to window further down to menu object also as a const reference

game.draw(const sf::RenderWindow & r)
{
   menu.draw(r);
}

Using the window reference, menu object draws some stuff.

menu.draw(const sf::RenderWindow & r)
{
    r.draw(/*draw some stuff here*/);
}


when I try to pass the window object by const reference I get an error
"overloads have no legal conversion for 'this' pointer"

Why can't I do this?
« Last Edit: September 05, 2012, 04:32:25 am by iride »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: cannot pass RenderWindow object by const reference
« Reply #1 on: September 05, 2012, 06:24:51 am »
Does it work without the const keyword?

You may also think about deriving your classes from sf::Drawable to get a imho nicer API call (window.draw(obj)).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: cannot pass RenderWindow object by const reference
« Reply #2 on: September 05, 2012, 10:56:40 am »
RenderWindow::draw is not const, therefore you can't call it on a const object.
Laurent Gomila - SFML developer

 

anything