- /*
*copvriqht(c)2016,烟台大学计算机学院
*All rights reserved.
*文件名称:test.cpp
*作者:陈传祯
*完成日期:2016年6月24日
*版本号:v1.0
*
*问题描述
*输入描述
*程序输出
*/ - #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;
- }
交通工具
最新推荐文章于 2019-06-24 16:29:58 发布