Skip to content

ofEventListeners with ofParameter in a lambda #8216

@chilina

Description

@chilina

Hey in the current nightly build, the following now has a linker (I think) error:

// in ofApp.h
	ofEventListeners listeners;
	ofParameter<int> paramTest;
// in ofApp::setup()
	paramTest.set("paramTest", 0, 0, 10);
	listeners.push(paramTest.newListener([this](const ofParameter<int>& p){
		std::cout << "paramTest listener called" << std::endl;
	}));

This was compiling in a nightly back from 9/30/24; the related forum thread is here: https://forum.openframeworks.cc/t/ofparameter-capture-in-lambda-with-ofeventlisteners/44170. dimitre thinks some template code (?) has changed in ofParameter.h between the two nightly builds.

Capturing an ofAbstractParameter for a listener with an ofParameterGroup still compiles OK:

	listeners.push(group.parameterChangedE().newListener([this](ofAbstractParameter& p){
		std::cout << "group listener called" << std::endl;
	}));

I'm not sure this usage capturing an ofParameter<> in a lambda is important from a design point of view, particularly since it has to be captured as const. I've always written the lambdas this way to be able to get access to the ofParameter stuff inside if I need it, like its min/max, or name, etc., and as a habit. But it's probably redundant, since the listener is on a specific ofParameter anyway. The exception might be if they're in a vector.

So there may be good reasons why the nightly has changed and I'm open to capturing a fundamental type instead of the whole ofParameter<>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions