ofParameter addListener doesn't match overloads


I am starting to use OpenFrameworks with ofxGui.

I have the following lines:

    primType2D.addListener(this, &ofApp::primDim2DChanged);

here are the declarations of primType2D and primDim2DChanged:

    ofParameter<bool> primType2D;
    bool primDim2DChanged();

On build, I fail with this:
'ofAddListener': none of the 5 overloads could convert all the argument types (compiling source file ofApp.cpp)

it originates from:

openFrameworks\types\ofParameter.h line 435

I have no idea what I’m doing wrong. I tried explicitly giving the priority and switching the bool function to a void function, but it doesn’t make any difference.

Hei there,

Have a closer look at the example provided, there you will see that ofParameter requires a type, and that type has to be passed as parameter to the listener function.
In your case, i would try something like that:

ofParameter<ofVec2f> primType2D;
bool primDim2DChanged(ofVec2f& value);

Well actually i don’t know if you want a boolean or a ofVec2f, either way will work.

I think I messed up with the formatting on the site, because I had a <bool> after the ofParameter so it was like you said. I didn’t have the other one on the other hand, so I’ll try it right away. Do I need to give it a bool or void return value?

I think you can give any return value you want… but not so sure… please give it a try.

the signature for the listener function can be any of:

void primDim2DChanged(bool & newValue);
void primDim2DChanged(const void * sender, bool & newValue);
bool primDim2DChanged(bool & newValue);
bool primDim2DChanged(const void * sender, bool & newValue);

the most common and what you usually want to use 90% of the times is the first one. for the rest:

const void* sender is a pointer to the original sender (in this case the ofParameter) that you ned to cast to the original type, if’s only useful if you have several events attached to the same listeners and want to know where they are comming from but it’s usually better to do this some other way

the bool return type can be used to mark an event as attended avoiding it to propagate to any more listeners if you return true from that function.