SFML community forums

Help => Window => Topic started by: iride on September 05, 2012, 04:29:03 am

Title: cannot pass RenderWindow object by const reference
Post by: iride 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?
Title: Re: cannot pass RenderWindow object by const reference
Post by: eXpl0it3r 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)).
Title: Re: cannot pass RenderWindow object by const reference
Post by: Laurent on September 05, 2012, 10:56:40 am
RenderWindow::draw is not const, therefore you can't call it on a const object.