C实现-CPP的-继承

来源:互联网 发布:大屏幕滚动抽奖软件 编辑:程序博客网 时间:2024/06/07 02:11
#include <stdio.h>#include <stdlib.h>struct Father {int num;void(*p_f)(struct Father * p);};void print_father(struct Father * p){ // 限定只能通过结构体来调用   printf("\n 爹给儿子留下了 %d元 人民币!" , p->num);}// --------------------- son struct Son {struct Father father; // 保留了一个对父类的引用    int num;void(*p_s)(struct Son * p);};void print_son(struct Son * p){printf("\n 儿子自己赚了 %d元 人民币!", p->num);}void main(){// init struct Son son;son.father.num = 1000; son.father.p_f = print_father;// callson.father.p_f(&son.father);//---------------son.num = 3000;son.p_s = print_son;son.p_s(&son);getchar();}


0 0
原创粉丝点击