SFML community forums
Help => Graphics => Topic started by: ElChupacabra on November 12, 2008, 12:25:54 am
-
This is the piece of Code troubling me:
void ClockString::Render(const RenderWindow &Window) const
{
time_string.SetText("Some Stuff");
Window.Draw(time_string);
}
ClockString is a class inherited from sf::Drawable. time_string is a Member of the type sf::String. The Problem is I get this error when compiling:
error: passing `const sf::String' as `this' argument of `void sf::String::SetText(const std::string&)' discards qualifiers
I'm not into the debts of c++. Can someone explain to me what is wrong here?
-
The const qualifier for the Render method is used to indicate that the method will not modify the object(instance of ClockString). You are modifying the object by calling the SetText method.
-
Thanks. Since the original Render function is const, how can I solve this?
-
Don't use SetText() in Render().
I believe you can also make time_string mutable (http://msdn.microsoft.com/en-us/library/4h2h0ktk.aspx).
-
Thanks, it worked :)[Making the time_string mutable]
-
This is not the solution, this is just a hack (in this context). Don't set the text in your Render function, that's a completely wrong design. You'd rather have an update() function to update your clock.