c语言实现基类和继承,详见inherit.c
/*****************inherit.c*****************/
#include
#include
char *get_name(char *age)
{
return age;
}
int get_age(int age)
{
return age;
}
typedef int (*func)(int);
typedef struct
{
char *name;
int age;
char *(*get_name)(char *);
int (*get_age)(int);
func handle;
}PERSON;
typedef struct
{
PERSON person;
char ***;
}MEN;
int main()
{
PERSON *person;
MEN *men = (MEN *)malloc(sizeof (*men));
men->person.name = "zozy";
men->person.age = 20;
men->person.get_name = get_name;
men->person.get_age = get_age;
men->person.handle = get_age;
men->*** = 1;
person = (PERSON *)men;
printf("person, name:%s age:%d age:%d\n", person->get_name(person->name), person->get_age(person->age), person->handle(person->age));
free(men);
return 0;
}
阅读(4155) | 评论(0) | 转发(0) |