Discussion:
event handler with parameters
(too old to reply)
Tim H
2010-07-16 04:22:07 UTC
Permalink
Hi,
I am working on using the event handler to call a function with a
variable. Basically, I have the 5 cards the user can pick as 5 separate
buttons. I also have a function that will play the ith card when the ith
button is selected. However, I do not want to make 5 functions (1 for
each button) so I made a function (cardButtonClicked(int)) that took in
this variable i. However, based on the documentation of mem_fun
(http://library.gnome.org/devel/libsigc++/stable/group__mem__fun.html#ga23120ad94420b72a8761423c5bab2bec),
I only need to add the initialization list. However, on compile, this
generates the error "invalid use of void expression" except I do not
know which void expression it is mentioning/what's going wrong.

Code (hand[i] is a button, (i) is the variable initialization list):
hand[i].signal_clicked().connect( sigc::mem_fun( *this,
&View::cardButtonClicked )(i) );

Thanks,
Tim Hsiung
CS 246 SE Tutor
2010-07-16 21:01:01 UTC
Permalink
Please see the sigc::bind function. Here is some info from the gtkmm
documentation:

http://library.gnome.org/devel/gtkmm-tutorial/unstable/sec-binding-extra-arguments.html.en

Also, there is a bit more about this in the tutorial slides from last
week and there are examples of its use in the given examples.
Post by Tim H
Hi,
I am working on using the event handler to call a function with a
variable. Basically, I have the 5 cards the user can pick as 5 separate
buttons. I also have a function that will play the ith card when the ith
button is selected. However, I do not want to make 5 functions (1 for
each button) so I made a function (cardButtonClicked(int)) that took in
this variable i. However, based on the documentation of mem_fun
(http://library.gnome.org/devel/libsigc++/stable/group__mem__fun.html#ga23120ad94420b72a8761423c5bab2bec),
I only need to add the initialization list. However, on compile, this
generates the error "invalid use of void expression" except I do not
know which void expression it is mentioning/what's going wrong.
hand[i].signal_clicked().connect( sigc::mem_fun( *this,
&View::cardButtonClicked )(i) );
Thanks,
Tim Hsiung
Continue reading on narkive:
Loading...