Last active
October 11, 2019 03:49
-
-
Save henriquegogo/1517d01b6a8ae5ccd5326f1d7c3b5d27 to your computer and use it in GitHub Desktop.
C Object Orientation Library
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
#ifndef COOL_H | |
#define COOL_H | |
#include <stdlib.h> | |
typedef struct object { | |
char *value; | |
void (*set)(); | |
char* (*get)(); | |
} object; | |
object* Object() { | |
object *this = malloc(sizeof(object)); | |
void set(char *value) { | |
this->value = value; | |
} | |
char* get() { | |
return this->value; | |
} | |
this->set = &set; | |
this->get = &get; | |
return this; | |
} | |
void init() { | |
object *henrique = Object(); | |
object *daiane = Object(); | |
henrique->set("Henrique"); | |
daiane->set("Daiane"); | |
printf("First: %s, second: %s\n", henrique->get(), daiane->get()); | |
free(henrique); | |
free(daiane); | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment