第10、11周-阅读程序(2)
来源:互联网 发布:联想电脑淘宝旗舰店 编辑:程序博客网 时间:2024/06/04 22:48
问题及代码:
/**Copyright (c) 2016,烟台大学计算机学院*All rights reserved.*文件名称 :*作 者 : 王艺霖*完成日期 : 2016年5月10号*版 本 号 : v1.0*问题描述 : 程序阅读*输入描述 :*程序输出 :*/#include <iostream>using namespace std;class A{public: A(){a=0;} A (int i){a=i;} void print(){cout<<a<<" ";}private: int a;};class B: public A{public: B(){b=0;} B(int i, int j, int k): A(i),aa(j){b=k;} //思考:这3处出现的print,有何区别 void print() //(1) { A::print(); //(2) aa.print(); //(3) cout<<b<<endl; }private: int b; A aa;};int main(){ B test[2]; test[0]=B(1,4,7); test[1]=B(2,5,8); for(int i=0; i<2; i++) test[i].print(); return 0;}
(1)这里的print作为一个函数出现。
(2)这里的print作为一个基类成员函数出现。
(3)这里的print作为一个派生函数出现。
运行结果:
1 4 7
2 5 8
0 0
- 第11周阅读程序(2)
- 第10、11周-阅读程序(2)
- 第10、 11 周--阅读程序1
- 第11周项目 程序阅读(2)
- 第10周阅读程序2
- 第11周阅读程序(1)
- 第11周阅读程序(3)
- 第11周阅读程序(4)
- 第2周阅读程序(2)
- 第13周程序阅读(2)
- 第14周程序阅读(2)
- 第2周阅读程序(1)
- 第13周-程序阅读(2)
- 第12周-阅读程序(2)
- 第12周阅读程序(2)
- 第13周-阅读程序(2)
- 第12周阅读程序(2)
- 第14周-阅读程序(2)
- 开发android硬件驱动程序-实现内核驱动程序模块
- 设计模式之六大原则——迪米特法则(LoD,LKP)
- eclipse3.7 安装反编译插件jad 《亲测可用》
- 数据库版本管理工具Flyway——基础篇
- 设计模式之六大原则——开闭原则(OCP)
- 第10、11周-阅读程序(2)
- 页面的五种布局以及嵌套
- android实现登录,Login姿势对不对?
- JVM必备指南
- Magento. How to create an attribute and apply it to products
- 虚拟总线上注册驱动
- 什么是需求分析
- 从源码层理解Hashtable中的put和get
- csdn博客如何添加图片