C实现-CPP的-多态
来源:互联网 发布:大屏幕滚动抽奖软件 编辑:程序博客网 时间:2024/06/07 15:23
#include <stdio.h>#include <stdlib.h>/**多态的本质:子类保留对父类的引用实现继承、同时通过改变父类的函数指针的值、来实现调用不同的方法。*/struct Student{void(*p)(); // 通过改变函数指针的值、来实现调用不同的方法。};struct MiddleStudent{struct Student stu;void(*p)();};struct SmallStudent{struct Student stu;void(*p)();};void middle_say(){printf("\n 中学生喜欢偶像剧!");}void small_say(){printf("\n 小学生喜欢动画片!");}void main(){struct MiddleStudent middle ;middle.p = middle_say ; middle.stu.p = middle.p;middle.stu.p();struct MiddleStudent small ;small.p = small_say ;small.stu.p = small.p;small.stu.p();printf("\n ----------------------------");// struct Student * stu1 = &middle.stu;struct Student * stu2 = &small.stu;stu1->p();stu2->p();// 实现了多态getchar();}
0 0
- C实现-CPP的-多态
- C实现-CPP的-封装
- C实现-CPP的-继承
- extern "C"----实现c cpp文件的混合编程
- 神奇的C&CPP
- C/Cpp的 typedef
- C语言链表的实现(修改版)Cpp文件
- c/c++头文件与cpp文件的切换实现
- 图邻接矩阵的c语言实现 graph_adj_matrix.cpp
- string.cpp的实现
- nms的cpp实现
- .C与.CPP的区别
- cpp和c的区别
- .c与.cpp的应用
- .c和.cpp 的 区别
- .c和.cpp的区别
- extern C配合__cplusplus实现CPP文件和C文件的函数互相调用
- c语言实现cpp中的引用传递
- 删除链表中重复元素
- tomcat端口8080被占的处理方法
- C实现-CPP的-封装
- 黑马程序员-IO流学习笔记-1
- C实现-CPP的-继承
- C实现-CPP的-多态
- 十六进制Unicode编码字符串与中文字符串的相互转换
- 分类器之adaboost
- Matlab函数linspace简介
- [转]如何写出杀手级简历
- 对 CNN facial point detection[CVPR2013]一文的实现
- HBase 批量导入测试
- Java学习日记(十二)反射
- 在github上参与开源项目日常流程