第十三周阅读程序1
来源:互联网 发布:成都学院软件邀请赛 编辑:程序博客网 时间:2024/06/05 19:38
/*Copyright (c) 2016,烟台大学计算机学院*All rights reserved.*文件名称 :*作 者 : 李钊*完成日期 : 2016年5月24号*版 本 号 : v1.0**问题描述 : 阅读程序*输入描述 :*程序输出 :*/#include<iostream>using namespace std;class A {int a;public: A():a(5){} virtual void print()const { cout<<a;}};class B: public A { char b;public: B() { b='E'; } void print() const { cout<<b; }};void show(A &x) { x.print(); }int main(){ A d1,*p; B d2; p=&d2; d1.print(); d2.print(); p->print(); show(d1); show(d2); return 0;}
运行结果:
5EE5E
分析:
A类为基类print成员函数为虚函数,B类为A类的派生类,B类中同样有相同名字的函数print在主函数中调用时覆盖基类中的虚函数所以输出5EE5E
0 0
- 第十三周阅读程序1
- 第十三周程序阅读1
- 第十三周阅读程序1
- 第十三周 程序阅读
- 第十三周 阅读程序
- 第十三周程序阅读
- 第十三周-阅读程序
- 第十三周-阅读程序
- 第十三周-阅读程序
- 第十三周--阅读程序
- 第十三周阅读程序
- 第十三周 阅读程序 1 虚函数
- 第十三周--阅读程序(1)
- 第十三周阅读程序1:虚函数
- 第十三周 阅读程序(1)
- 第十三周 课后实践:阅读程序1
- 第十三周阅读程序(1)
- 第十三周项目训练1 阅读程序
- Unity动画事件
- base64加密解密
- JS 变量声明提升(Hoisting)
- xUtils更新到3.0后的基本使用规则
- win/linux下使用eclipse的一些小技巧
- 第十三周阅读程序1
- XSplit简称XS,它的作用就是录制视频/直播视频。
- MongoDB windows64及32位安装
- 第十三周项目2-动物这样叫(2)
- 内核模块操作指令
- htc vive安装到玩流程体验
- Leetcode 349. Intersection of Two Arrays
- 异形卵
- Android Studio 入门