第十三周项目—阅读、修改和运行关于交通工具类的程序(1)
2016-05-26 12:13
295 查看
#include <iostream> using namespace std; class Vehicle//交通工具 { public: 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; }运行结果:程序分析:基类成员函数不是虚函数,所以指针仍然指向基类
相关文章推荐
- 欢迎使用CSDN-markdown编辑器
- USACO : transform(将输入字符串进行rotate,reflect)
- ffmpeg-20160525-git-bin
- 【计算机视觉】多目标跟踪代码
- 小马哥---高仿红米note A6-4.1-20140709(背贴A6-40M1-TD-V3.00刷机拆机主板图与开机识别图
- arrayList 和hashSet的区别
- 【Thrift一】Thrift编译安装
- 至今31天,熊厂,你怎么了?
- java process.waitfor 返回1 解决
- PowerPoint课件制作技巧集锦
- 杨辉三角
- https 出现host name not match 问题
- Nested List
- codeforces 676D Theseus and labyrinth BFS搜索
- 【JAVA框架】Hibernate 与Mybatis 区别
- UVA 11582 Colossal Fibonacci Numbers!
- 从浅到深了解Thrift(三)
- Biological Filtration
- 使用Spring MVC 配置
- qsort()