#include #include #include "person_v2.h" #include "student_v2.h" static void _run_person_methods(Person *p) { char *p_str = p->vtable[PERSON_TOSTRING](p); printf("%s", p_str); // Print out their name. free(p_str); // Check out the accessor! printf("get_name accessor returns: %s\n", (char*)p->vtable[PERSON_GET_NAME](p)); } static void _run_student_methods(Student *s) { // Run through all of the inherited methods first! _run_person_methods((Person *)s); // Run the new methods! printf("student_get_id accessor returns %d\n", (unsigned int)s->vtable[STUDENT_GET_ID](s)); printf("setting the id. . .\n"); int res = s->vtable[STUDENT_SET_ID](s, 12345); if (!res) { printf("Hooray! Student ID set! It's now: %d\n", (unsigned int)s->vtable[STUDENT_GET_ID](s)); } } static void _person_test(void) { // Let's make a person! Person *p = person_new("Donald Knuth"); _run_person_methods(p); p->vtable[PERSON_DELETE](p); } static void _student_test(void) { Student *s = student_new("James Okada", 920291); _run_student_methods(s); s->vtable[STUDENT_DELETE](s); } int main(int argc, char **argv) { printf("======================\n\n"); _person_test(); printf("\n-----------------------------\n\n"); _student_test(); printf("\n======================\n"); return EXIT_SUCCESS; }