Skip to content

Instantly share code, notes, and snippets.

@kevinlynx
Last active August 29, 2015 14:04
Show Gist options
  • Save kevinlynx/f7725e42e81b0608342b to your computer and use it in GitHub Desktop.
Save kevinlynx/f7725e42e81b0608342b to your computer and use it in GitHub Desktop.
define local function in c++
#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