阅读程序1
来源:互联网 发布:网络造谣举报 编辑:程序博客网 时间:2024/06/06 19:52
/* *Corpyright (c)2013,烟台大学计算机学院 *All right reseved. *作者:张凯*完成日期:2014年5月27日 *版本号:v1.0 *输入描述: *问题描述: *程序输出: *问题分析: *算法设计: */ #include <iostream>using namespace std;class Vehicle //交通工具{public: virtual void run() const {cout<<"run a vehicle."<<endl;}};class Car: public Vehicle //汽车{public: void run() const { cout << "run a car. "<<endl; }};class Airplane: public Vehicle //飞机{public: void run() const { cout << "run a airplane. "<<endl; }};int main(){ cout<<"(a) 直接用对象访问成员函数: "<<endl; Vehicle v; v.run(); Car car; Airplane airplane; car.run(); airplane.run(); cout<<"(b)用指向基类的指针访问成员函数: "<<endl; Vehicle *vp; vp=&car; vp->run(); vp=&airplane; vp->run(); return 0;}//(1)当基类的指针指向派生类,用指针调用同名成员函数,执行的是基类的成员函数。//(2)当基类的指针指向派生类,用指针调用同名成员函数,执行的是的派生类的成员函数。// (3) 当基类的指针指向派生类,用指针调用同名成员函数,执行的是的派生类的成员函数。
0 0
- noip2012 阅读程序1
- 11-阅读程序1
- 阅读程序1
- 阅读程序1
- 12程序阅读1
- 阅读程序1
- 阅读程序(1)
- 程序阅读1
- 阅读程序1、2
- 阅读程序补充-1
- 阅读程序1
- 阅读程序(1)
- 阅读程序1
- 阅读程序(1)
- 阅读程序(1)
- 14-阅读程序1-1
- 16-1阅读程序1
- 第十一周阅读程序1
- Oracle之数据库一致性读的原理
- 《老罗Android》学习之Content Provider
- 测试测试
- android adb push 命令
- oracle调优 浅析关联设计
- 阅读程序1
- matlab造波表
- LeetCode: Valid Number [066]
- Tomcat 项目路径问题
- chrome浏览器全屏
- Android 中屏幕点击事件的实现
- android adb 查看ip地址命令
- “父亲节”为程序员正名——谁说程序员不会表达爱?
- gcc omit-frame 如何找到函数的第一个参数