- 25
- 0
- 约1.15万字
- 约 41页
- 2017-02-24 发布于上海
- 举报
虚函数
虚函数 思考:为什么要引入虚函数//test_virtual.cpp 【例4】没有使用虚函数的例题。 #includeiostream.h class base /定义基类base { public: void who() {coutthis is the class of base!endl;} }; class derive2 : public base //定义派生类derive2{ public: void who() {coutthis is the class of derive2!endl;} };void main(){ base obj,*ptr; derive1 obj1; derive2 obj2; ptr = obj; ptr-who(); ptr=obj1; //指向第一个子类 ptr-who(); ptr=obj2; //指向第二个子类 ptr-who(); obj1.who(); //分别指向子类 obj2.who();程序运行结果: This is the class of base! (a) This is the class of bas
您可能关注的文档
最近下载
- Unit 7 A Good Read课时4 Section B 1a-1e(教学评教学设计)英语新教材人教版八年级下册.docx
- 欧洲规范-NF P94-093-中文版.pdf VIP
- 医院检验科网络应急预案.docx VIP
- 环境监测采样培训课件.pptx VIP
- 操作系统期末复习题及答案.docx VIP
- 环境监测采样前的准备及水样类型80课件.pptx VIP
- 安全生产费用监理实施细则.docx
- 《变幻的空间》 课件 2026浙美版美术八年级下册.ppt
- (2025年)环境监测现场采样人员转正考核试题附答案(水和废水采样).docx VIP
- 环境监测现场采样人员综合测试题(含答案).docx VIP
原创力文档

文档评论(0)