Delegate function to annother class

Hey Guys,

I have a quite beginner doubt about how could i pass a reference function from c lass to another.

Let’s assume that i have a class

class ContentLoader
{
public:
void onComplete();
}

Houw could i do something like that ?

void ofApp::setup()
{
ContentLoader c;
c.onComplete = onComplete;
}

void ofApp::onComplete()
{

}

I’ve seen things about std::bind but i couldn’t make it happen properly.

Thanks !

std::function is the easiest

class ContentLoader{
public:
std::function onComplete;
}

void ofApp::setup(){
    c.onComplete = onComplete;
}

onComplete can be a pure c function (ie: not a member of ofApp) or a lambda like:

c.onComplete = [&]{
    cout << "complete!!" << endl;
};

That’s great arturo ! Thanks for that.