Created
October 18, 2011 08:44
-
-
Save bertzzie/1294950 to your computer and use it in GitHub Desktop.
C OO
This file contains 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
// Credits to nategoose (http://stackoverflow.com/questions/351733/can-you-write-object-oriented-code-in-c/2733004#2733004) | |
// modified for clarity | |
struct stack { | |
struct stack_type * type; | |
// privates | |
}; | |
struct stack_type { | |
void (* construct)(struct stack * this); | |
struct stack * (* operator_new)(); | |
void (*push)(struct stack * this, thing * t); | |
thing * (*pop)(struct stack * this); | |
int class_member; | |
}Stack = { | |
.construct = stack_construct, | |
.operator_new = stack_operator_new, | |
.push = stack_push, | |
.pop = stack_pop | |
}; | |
stack(struct stack *construct); | |
// others.. | |
int main(int argc, char** argv) | |
{ | |
struct stack * st = Stack.operator_new(); | |
if (!st) { | |
} else { | |
st->type.push(st, thing2); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment