SFML community forums

Help => Graphics => Topic started by: ElChupacabra on November 12, 2008, 12:25:54 am

Title: Weird Error
Post by: ElChupacabra on November 12, 2008, 12:25:54 am
This is the piece of Code troubling me:
Code: [Select]

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:
Quote

 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?
Title: Weird Error
Post by: Tungsten on November 12, 2008, 12:43:19 am
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.
Title: Weird Error
Post by: ElChupacabra on November 12, 2008, 12:58:46 am
Thanks. Since the original Render function is const, how can I solve this?
Title: Weird Error
Post by: Wizzard on November 12, 2008, 01:36:58 am
Don't use SetText() in Render().

I believe you can also make time_string mutable (http://msdn.microsoft.com/en-us/library/4h2h0ktk.aspx).
Title: Weird Error
Post by: ElChupacabra on November 12, 2008, 01:45:43 am
Thanks, it worked :)[Making the time_string mutable]
Title: Weird Error
Post by: Laurent on November 12, 2008, 07:53:38 am
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.