#include #include // Interface struct Interface { int foo; void (*bar)(); }; // First class, type one void one_class_bar () { printf("OneClass.Bar()\n"); } struct OneClass { int foo; void (*bar)(); }; // Second class, type two void two_class_bar () { printf("TwoClass.Bar()\n"); } struct TwoClass { int foo; void (*bar)(); }; // The polymorphism typedef union { struct Interface i; struct OneClass o; struct TwoClass t; } Object; int main () { struct OneClass o; struct TwoClass t; // Binding the functions to the classes o.bar = &one_class_bar; t.bar = &two_class_bar; // Creating a list Object list[2]; // Filling the list list[0] = (Object) o; list[1] = (Object) t; // Running the two methods list[0].i.bar(list[0]); list[1].i.bar(list[1]); return 0; }