[toc]

一、准备

c语言结构体使用函数与继承

main.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//main.c
#include "stdio.h"


typedef int (*Operation)(int a, int b);
void fun();
typedef struct Animal {
int a;
Operation opt;
}Animal;
typedef struct Cat {
Animal;
}Cat;

int main()
{
Cat c;
c.a = 2;
printf("%d\n", c.a);
Animal animal;
animal.opt = fun;
animal.opt(5, 3);
animal.opt(5, 3);
printf("sfas\n");
return 0;
}

void fun()
{
printf("fun\n");
}