Welcome,
Guest
. Please
login
or
register
. Did you miss your
activation email?
French forum
Home
Help
Search
Login
Register
SFML community forums
»
Help
»
Window
»
pollEvent() strange const behaviour
Print
Pages: [
1
]
Author
Topic: pollEvent() strange const behaviour (Read 1886 times)
0 Members and 1 Guest are viewing this topic.
netrick
Full Member
Posts: 174
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
»
Logged
Laurent
Administrator
Hero Member
Posts: 32498
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.
Logged
Laurent Gomila - SFML developer
Print
Pages: [
1
]
SFML community forums
»
Help
»
Window
»
pollEvent() strange const behaviour