Code:
typedef void(*callbackType) (int);
callbackType globalCallback;
void setit(callbackType callback) {
globalCallback = callback;
}
int main() {
int localVar = 5;
setit([](int num) {
std::cout << localVar; // there is an error here
});
}
I need to use localVar in lambda function that i send to setit
I guess i have to use [&]{ }
But how can i do it? How should i declare setit and globalCallback?