/* Actually, this part's supposed to be preprocessed... */ #include #include /* The following should be directly inserted by c+=5e-1 */ #include "classes.h" /* And this is adapted from the c5 file */ int main(int argc, char** argv) { struct Animal_i** zoo; struct Animal_i** zoo_p; int i; if (argc == 1) return EXIT_SUCCESS; /* Populate the zoo */ zoo = malloc(sizeof(struct Animal*) * argc); for (i = 1; i < argc; i++) { switch (tolower(*argv[i])) { case 'd': printf("Creating Doggy\n"); zoo[i - 1] = (struct Animal_i*) _Doggy_class.__create__(&_Doggy_class); break; case 'k': printf("Creating Kitty\n"); zoo[i - 1] = (struct Animal_i*) _Kitty_class.__create__(&_Kitty_class); break; default: printf("Creating Animal\n"); zoo[i - 1] = (struct Animal_i*) _Animal_class.__create__(&_Animal_class); } } zoo[argc - 1] = NULL; printf("\n"); /* Do stuff */ for (zoo_p = zoo; *zoo_p; zoo_p++) { printf("%s->noise(): ", (*zoo_p)->__class__->name); ((struct Animal_c*)(*zoo_p)->__class__)->noise( (struct Animal_i*)*zoo_p); } printf("\n"); /* Clean up */ for (zoo_p = zoo; *zoo_p; zoo_p++) { printf("Destroying %s\n", (*zoo_p)->__class__->name); ((struct Object_c*)(*zoo_p)->__class__)->__del__( (struct Object_i*)*zoo_p, (struct Object_c*)(*zoo_p)->__class__->super); } free(zoo); return EXIT_SUCCESS; } /* vim:syntax=c: */