Created
January 28, 2018 15:04
-
-
Save Thrimbda/0afb2b06e772d0a8df39606ceded05f9 to your computer and use it in GitHub Desktop.
OOP in C
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
| #include <stdio.h> | |
| #include <stdlib.h> | |
| typedef struct Class{ | |
| int a; | |
| int (*generator)(struct Class *this); | |
| }Class; | |
| int func(struct Class *this){ | |
| this->a++; | |
| printf("%d", this->a); | |
| } | |
| Class *ClassCtreator(){ | |
| Class *this; | |
| this = (Class*)malloc(sizeof(Class)); | |
| this->a = 0; | |
| this->generator = func; | |
| return this; | |
| } | |
| int main() | |
| { | |
| Class *p = ClassCtreator(); | |
| p->generator(p); | |
| printf("%d", p->a); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment