In my experience in object oriented C programming I have seen two ways to implement derived classes.
First Method, have a definition of the parent class as a .h file. Then each class that derives from this class will have do:
File parent_class.h:
int member1;
int member2;
File testing.c:
struct parent_class {
#include "parent_class.h" // must be first in the struct
}
struct my_derived_class {
#include "parent_class.h" // must be first in the struct
int member3;
int member4;
}
Second Method, would do:
File testing.c:
struct parent_class {
int member3;
int member4;
}
struct my_derived_class {
struct parent_class; // must be first in the struct
int member3;
int member4;
}
What is your favorite method of doing derived classes in C ( doesn't have to be what I have done )? and why?
Which method would you prefer, first or second method ( or your own )?