C++中,虚函数与容器(vector)的巧妙组合
来源:互联网 发布:淘宝账号冻结怎么解除 编辑:程序博客网 时间:2024/06/05 10:33
#include <iostream>
#include <vector>
using namespace std;
class base //纯虚基类
{
public:
virtual void init() = 0;
virtual void start() = 0;
virtual void end() = 0;
};
class other1
{
public:
void logprint1()
{
cout<<"print err1"<<endl;
};
};
class other2
{
public:
void logprint2()
{
cout<<"print err2"<<endl;
};
};
class rea1:public other1,public base
{
public:
void init()
{
cout<<"rea1"<<endl;
};
void start()
{
cout<<"start1"<<endl;
};
void end()
{
cout<<"end1"<<endl;
logprint1();
};
};
class rea2:public other2,public base
{
public:
void init()
{
cout<<"rea2"<<endl;
};
void start()
{
cout<<"start2"<<endl;
};
void end()
{
cout<<"end2"<<endl;
logprint2();
};
};
int main()
{
vector<base *> myvec;
vector<base *>::iterator itr;
rea1 crea1;
rea2 crea2;
myvec.push_back(&crea1);
myvec.push_back(&crea2);
for (itr = myvec.begin(); itr != myvec.end(); itr++) //打印出来
{
(*itr)->init();
(*itr)->start();
(*itr)->end();
}
return 0;
}
- C++中,虚函数与容器(vector)的巧妙组合
- C++STL中vector容器 begin()与end()函数、front()与back()的用法
- C++STL中vector容器 begin()与end()函数、front()与back()的用法
- C++STL中vector容器 begin()与end()函数、front()与back()的用法
- C++STL中vector容器 begin()与end()函数、front()与back()的用法
- C++STL中vector容器 begin()与end()函数、front()与back()的用法
- C++STL中vector容器 begin()与end()函数、front()与back()的用法
- [C++]STL中vector容器 begin()与end()函数、front()与back()的用法
- C++STL中vector容器 begin()与end()函数、front()与back()的用法
- C++STL中vector容器 assign()函数的用法
- 【C++】vector容器和list容器中使用单个迭代器的erase函数学习笔记
- vector -- STL中容器的常用函数
- C++STL中vector容器的用法
- C++STL中vector容器的用法
- C++STL中vector容器的用法
- C++STL中vector容器的用法
- C++STL中vector容器的用法
- C++STL中vector容器的用法
- 查看进程启动时间(精确到s)
- mac编译live555 for iphone
- Linux系统下安装 apache2.4.1的过程
- Hibernate中的缓存
- ArcGIS服务分析及问题处理
- C++中,虚函数与容器(vector)的巧妙组合
- 背景建模与前景检测之三(Background Generation And Foreground Detection Phase 3)
- $lt(<) $lte(<=) $gt(>) $gte(>=) $ne(!=) $in $not $size $where limit(5).skip(5).sort({"number" : -1}
- EmuMaster加载中文名的游戏
- MySQL-数据库设计概论
- JAVA中的集合
- 同一i2c接受不同地址的操作
- 自动动手写发包工具
- 转抄的一些借口