I was trying to understand the difference between closures and function pointers, and I came across this answer in SO
What I don’t understand is this code
BOOL (*lessThanTest)(int);
int lessThan = 100;
lessThanTest = &LessThan;
BOOL LessThan(int i) {
return i < lessThan; // compile error - lessThan is not in scope
}
Why there is a compile error consideringn that lessThan is a global variable, it can be accessed from within LessThan function, did I miss something?
EDIT
This is not my code, it’s taken from an answer in SO Function pointers, Closures, and Lambda
You missed a paragraph in that answer:
In what you posted,
int lessThanis not meant at global scope, it should be assumed to be in a function somewhere.