f1409.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:
C#编程
开发平台:
Visual C++
- //=====================================
- // f1409.cpp
- // 动多态编程
- //=====================================
- #include"house.h"
- #include"cari.h"
- #include<iostream>
- #include<vector>
- using namespace std;
- //-------------------------------------
- void openHouse(House& a){
- a.open();
- }//------------------------------------
- void openCar(const vector<Car*>& bs){
- for(unsigned i=0; i<bs.size(); ++i)
- bs[i]->open();
- }//------------------------------------
- int main(){
- House xa;
- openHouse(xa);
- Car21 b21;
- Car2 b2;
- Car1 b1;
- Car22 b22;
- vector<Car*> vb;
- vb.push_back(&b21);
- vb.push_back(&b2);
- vb.push_back(&b1);
- vb.push_back(&b22);
- openCar(vb);
- }//====================================