void foo(void (*)(long v)) {}
auto makeBar(long baz) {
return [=](long v) {
std::cout << "hello from closure " << baz;
};
}
int main() {
auto bar = makeBar(2);
foo(bar);
return 0;
}
Hi,
I'm trying to do the above. Essentially create a curried function makeBar which receives a parameter baz. then instantiate it and pass the result to function foo.
the following does not compile. Specifically the call to foo(bar). If I remove the capture [=] it compiles, but then I can't use baz within the curry.
How can this be done?
Aucun commentaire:
Enregistrer un commentaire