SFML community forums

Help => Graphics => Topic started by: Martin Lefevre on April 14, 2020, 05:49:02 pm

Title: Cannot call draw() from constant RenderTarget object.
Post by: Martin Lefevre 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?
Title: Re: Cannot call draw() from constant RenderTarget object.
Post by: Laurent 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.