On Sat, May 16, 2015 at 2:35 PM, Edward Diener
On 5/16/2015 3:04 PM, Emil Dotchevski wrote:
On Sat, May 16, 2015 at 11:50 AM, Edward Diener
wrote: I assume that the purpose of having the signal type be a pointer to a
function taking some data and returning an incomplete type instead of
returning void is to make each signal type unique. But is this really necessary ?
It is necessary so that if you have:
typedef struct button_down_(*button_down)(int x, int y);
you can tell it apart from
typedef struct button_up_(*button_up)(int x, int y);
I understand that the types are different but when would you ever use that knowledge in code ?
It seems you're asking why are different signals necessary, e.g. why would I need to discriminate between a "button down" and a "button up" event -- which is puzzling. Anyway, the answer is that you need different signals so that you can tell connect<> which signal you're connecting (and emit<> which signal you're emitting) from the specified emitter object:
void handle_button_down( int x, int y ); void handle_button_up( int x, int y );
auto c1=connect
(e,&handle_button_down); auto c2=connect (e,&handle_button_up); typedef void (*button_down)(int x, int y); typedef void (*button_up)(int x, int y);
void handle_button_down( int x, int y ); void handle_button_up( int x, int y );
auto c1=connect
(e,&handle_button_down); auto c2=connect (e,&handle_button_up); Is there some reason why the above would not work ?
Yes, the reason is that in that case button_down and button_up are the same type void(*)(int,int), so they'd be the same signal. -- Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode