C Unions and Polymorphism [duplicate]
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How can I simulate OO-style polymorphism in C? I'm trying to use unions to create polymorphism in C. I do the following. typedef struct{ ... ... } A; typedef struct{ ... ... } B; typedef union{ A a; B b; }C; My question is: how can I have a method that takes type C, but allows for A and B's also. I want the following to work: If I define a function: myMethod(C){ ... } then, I want this to work: main(){ A myA;