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

Author Topic: pollEvent() strange const behaviour  (Read 719 times)

0 Members and 1 Guest are viewing this topic.

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
pollEvent() strange const behaviour
« on: January 10, 2013, 08:33:33 pm »
The pseudo code:
std::vector <sf::Event> pressedButtons;
sf::Event event;

while (window->pollEvent(event))
{
            if (event.type == sf::Event::MouseButtonPressed)
                {
                        pressedButtons.push_back(event);
                }
}

sf::Event * isPressed(sf::Mouse::Button button) const
{
        for (unsigned int i = 0; i < pressedButtons.size(); i++)
        {
                if (pressedButtons[i].mouseButton.button == button) return & pressedButtons[i]; //compile error
                else return nullptr;
        }
}
 

The error on that line is error: invalid conversion from ‘const value_type* {aka const sf::Event*}’ to ‘sf::Event*’ [-fpermissive]. But why? The event object where pollEvent saves the event isn't a cost object, what's wrong here?
« Last Edit: January 10, 2013, 08:35:07 pm by netrick »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: pollEvent() strange const behaviour
« Reply #1 on: January 10, 2013, 08:39:35 pm »
You're inside a const member function, therefore all members are const, therefore pressedButtons is const, therefore pressedButtons[ i ] is const.
Laurent Gomila - SFML developer

 

anything