Created
September 2, 2018 21:25
-
-
Save mehmetaydogduu/bb557f7235232863c302ce3b2b2c11c7 to your computer and use it in GitHub Desktop.
C - function inside struct - Javascript Like Solution
This file contains hidden or 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
# Copy from https://stackoverflow.com/a/32964582/7595238 | |
#include <stdio.h> | |
typedef struct hello { | |
int (*someFunction)(); | |
} hello; | |
int foo() { | |
return 0; | |
} | |
hello Hello() { | |
struct hello aHello; | |
aHello.someFunction = &foo; | |
return aHello; | |
} | |
int main() | |
{ | |
struct hello aHello = Hello(); | |
printf("Print hello: %d\n", aHello.someFunction()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment