#include #include #include class Animal { void noise() {printf("Generic animal noise.\n");} }; class Doggy: Animal { void __init__(Doggy* self) {printf("Hi.\n");} void noise(Doggy* self) {printf("Bow wow.\n");} }; class Kitty: Animal { void __init__(Kitty* self) {Kitty.num++;} void __del__(Kitty* self) {printf("Bye!\n");} void noise(Kitty* self) {printf("Meow, I say. I'm #%i.\n", Kitty.num);} static int num = 0; }; int main(int argc, char** argv) { Animal* zoo; Animal* zoo_p; int i; if (argc == 1) return EXIT_SUCCESS; /* Populate the zoo */ zoo = malloc(sizeof(Animal) * argc); for (i = 1; i < argc; i++) { switch (tolower(*argv[i])) { case 'd': printf("Creating Doggy\n"); zoo[i - 1] = Doggy(); break; case 'k': printf("Creating Kitty\n"); zoo[i - 1] = Kitty(); break; default: printf("Creating Animal\n"); zoo[i - 1] = Animal(); } } zoo[argc - 1] = NULL; printf("\n"); /* Do stuff */ for (zoo_p = zoo; *zoo_p; zoo_p++) { printf("%s->noise(): ", zoo_p->name); zoo_p->noise(); } printf("\n"); /* Clean up */ for (zoo_p = zoo; *zoo_p; zoo_p++) { printf("Destroying %s\n", zoo_p->name); del(*zoo_p); } free(zoo); return EXIT_SUCCESS; } /* vim:syntax=c: */