Skip to content

Instantly share code, notes, and snippets.

@Thrimbda
Created January 28, 2018 15:04
Show Gist options
  • Select an option

  • Save Thrimbda/0afb2b06e772d0a8df39606ceded05f9 to your computer and use it in GitHub Desktop.

Select an option

Save Thrimbda/0afb2b06e772d0a8df39606ceded05f9 to your computer and use it in GitHub Desktop.
OOP in C
#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