Last active
August 29, 2015 14:04
-
-
Save kevinlynx/f7725e42e81b0608342b to your computer and use it in GitHub Desktop.
define local function in c++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define deflocal(name, ret, body) \ | |
struct name { \ | |
ret operator() body \ | |
} | |
#define callocal(name) name() | |
int main() { | |
// example | |
deflocal(hello, char*, (const char *from, const char *to) { | |
printf("%s say hello to %s\n", from, to); | |
return "work"; | |
}); | |
char *r = callocal(hello)("kev", "she"); | |
printf("result: %s\n", r); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment