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

Author Topic: Weird Error  (Read 3858 times)

0 Members and 1 Guest are viewing this topic.

ElChupacabra

  • Newbie
  • *
  • Posts: 7
    • View Profile
Weird Error
« 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?

Tungsten

  • Newbie
  • *
  • Posts: 4
    • View Profile
Weird Error
« Reply #1 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.

ElChupacabra

  • Newbie
  • *
  • Posts: 7
    • View Profile
Weird Error
« Reply #2 on: November 12, 2008, 12:58:46 am »
Thanks. Since the original Render function is const, how can I solve this?

Wizzard

  • Full Member
  • ***
  • Posts: 213
    • View Profile
Weird Error
« Reply #3 on: November 12, 2008, 01:36:58 am »
Don't use SetText() in Render().

I believe you can also make time_string mutable.

ElChupacabra

  • Newbie
  • *
  • Posts: 7
    • View Profile
Weird Error
« Reply #4 on: November 12, 2008, 01:45:43 am »
Thanks, it worked :)[Making the time_string mutable]

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Weird Error
« Reply #5 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.
Laurent Gomila - SFML developer