Mismatched types in static event

I need an object of class Clip to be loaded into another object of class ClipEditor (there will be multiple objects of Clip class and one object of ClipEditor class).

To do so, i think the best way is to create a static event inside Clip class, so all instances of that class broadcast the event to a single listener (the ClipEditor instance). In detail, once the Clip object is selected, it notifies to the static event and passes its memory address, so the listener executes the callback function with the selected clip’s memory address.

Obviously it does not work, and i get this error on the compiler:

/home/ivan/OF/libs/openFrameworks/events/ofEventUtils.h:103:6: note: template argument deduction/substitution failed:

/home/ivan/OF/apps/myApps/seq_6/src/ClipEditor.cpp:7:55: note: mismatched types ‘bool(ArgumentsType&)’ and ‘ClipEditor’ ofAddListener(Clip::e_select, this, &ClipEditor::load);

this is the related code:

//static event declaration in Clip.h
static ofEvent <Clip*> e_select;

//static event initialization outside Clip class scope
ofEvent <Clip*> Clip::e_select;

//adding the listener in  ClipEditor.cpp (inside ClipEditor's constructor)
ofAddListener(Clip::e_select, this, &ClipEditor::load);

//the callback function
void ClipEditor::load(Clip* _clip){}


1- as i undestood, the event type must be the same data type as the value passed by ofNotifyEvent(), in this case that would be ofNotifyEvent(eventName, objAddress), am i right?

thanks in advance

It’s a little tricky to tell what’s going on from your code without seeing it in context …

I don’t quite understand what

//static event initialization outside Clip class scope
ofEvent <Clip*> Clip::e_select;

is doing. If the e_select is a static member of the Clip class, it is initialized through its default constructor I believe.

Double check to make sure that the method signature is the same in your header and implementation …

Based on your error I believe you might have

void ClipEditor::load(Clip* _clip){}

in your ClipEditor.cpp file, but perhaps you have

bool load(Clip* _clip);

in your ClipEditor.h header file?

Everything else looks ok as far as I can tell.

There are lots of different method signatures for event callbacks. The non-void return value callbacks allow the message to be “consumed” by returning false (e.g. it’s a message to the event system that the event has been “handled” and it should not continue passing that event to other listeners.

Also, if you use a pointer for your templated ofEvent, you may need to adjust it. If I recall, the callback function should actually be a reference … so your signature would probably look like (and this is strange).

void load(Clip*& _clip);

Perhaps consider just using ofEvent<Clip>. Then when you notify the event, you’ll send it a reference …

i tried passing by reference and it worked, this event subject has been a bit tricky to figure out since i can’t find specific documentation about how ofAddListener work. and i am just starting with c++ so templates might be hard to understand for me at this moment.