博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
责任链模式(C++)
阅读量:6878 次
发布时间:2019-06-26

本文共 1026 字,大约阅读时间需要 3 分钟。

#include 
#include
using namespace std;class relatives{public: relatives(){} virtual ~relatives(){} virtual bool request(int)=0;};class brother : public relatives{public: brother(){} virtual ~brother(){} bool request(int num) { if (num<100) { cout<<"哥哥给你买"<
p_vbuy;public: buysomething() { p_vbuy.push_back(new brother); p_vbuy.push_back(new mother); p_vbuy.push_back(new father); } virtual ~buysomething() { p_vbuy.clear(); } void request(int num) { bool flag=false; for (vector
::iterator it=p_vbuy.begin();it!=p_vbuy.end();it++) { flag=(*it)->request(num); if (flag==true) break; } }};int main(){ buysomething *buy=new buysomething; buy->request(6000); delete buy; system("pause"); return 0;}

转载于:https://www.cnblogs.com/tiandsp/archive/2012/06/27/2565629.html

你可能感兴趣的文章
使用 LogStash 归集日志
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
德国博世百年风雨启示录(下):实业强国
查看>>
(整理)用Elixir做一个多人扑克游戏 4
查看>>
关于架构
查看>>
The application’s PagerAdapter changed the adapter’s contents without calling PagerA
查看>>
qcom 跨平台的串口调试工具 PKGBUILD
查看>>
Delphi 时间格式化,动态显示时间,显示最新时间
查看>>
在JAVA中将NEW一分为2,分步进行[反射机制产生类]
查看>>
Java多态性的两个特殊情况
查看>>
我的友情链接
查看>>
怎么改变Win7登陆背景图片
查看>>
虚拟带库和物理带库比较
查看>>
AD委派加域权限
查看>>
在Delphi 7中使用加密的SQLite
查看>>
wordpress 无用的RSS Feed Cache
查看>>
Linux Vi编辑器的基本使用方法
查看>>
HTTP头域列表与解释 之 response篇
查看>>
一切属他,则名为苦;一切由己,自在安乐。
查看>>