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

Author Topic: Cannot call draw() from constant RenderTarget object.  (Read 1431 times)

0 Members and 1 Guest are viewing this topic.

Martin Lefevre

  • Newbie
  • *
  • Posts: 6
    • View Profile
Cannot call draw() from constant RenderTarget object.
« on: April 14, 2020, 05:49:02 pm »
Hi,
I made a function that is supposed to draw a text on a RenderTarget. But I an error message saying that "No instance of overloaded function could be found.". Here is my function:
void DrawStringInBox(const sf::RenderTarget &xindox, const std::string& String, const sf::Font& font) {
        sf::Text text(String, font);
        xindox.draw(text);
}

But, it works fine when I remove the const before the RenderTarget:
void DrawStringInBox(sf::RenderTarget &xindox, const std::string& String, const sf::Font& font) {
        sf::Text text(String, font);
        xindox.draw(text);
}

Why? Isn't draw() a const function? And if it isn't, why wouldn't it be?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Cannot call draw() from constant RenderTarget object.
« Reply #1 on: April 14, 2020, 06:07:55 pm »
It is const for the object that you draw. It is not const for the render-window, because it is obviously modified by the call.
Laurent Gomila - SFML developer

 

anything