SFML community forums

Help => Window => Topic started by: netrick on January 10, 2013, 08:33:33 pm

Title: pollEvent() strange const behaviour
Post by: netrick 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?
Title: Re: pollEvent() strange const behaviour
Post by: Laurent 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.