当前位置: 首页 > news >正文

动漫网站建设赚钱吗网站建设哪些资质

动漫网站建设赚钱吗,网站建设哪些资质,重庆搜索引擎优化,wordpress后台乱码参考大话设计模式; 详细内容参见大话设计模式一书第十四章,该书使用C#实现,本实验通过C语言实现。 观察者模式又叫做发布-订阅(Publish/Subscribe)模式。 观察者模式定义了一种一对多的依赖关系,让多个观察…

参考大话设计模式;

详细内容参见大话设计模式一书第十四章,该书使用C#实现,本实验通过C++语言实现。

观察者模式又叫做发布-订阅(Publish/Subscribe)模式。

观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象。这个主题对象在状态发生变化时,会通知所有观察者对象,使它们能够自动更新自己。[DP] 

一 学习测试代码 

书上的模式学习图

 我自己的测试UML图

测试代码:

#include <iostream>
#include <list>
using namespace std;class guanchazhe{
public:virtual void update() = 0;
};class xiaozhang :public guanchazhe{
public:virtual void update(){cout << "小张收到" << endl;}
};class xiaowang :public guanchazhe{
public:virtual void update(){cout << "小王收到" << endl;}
};class tongzhizhe{
protected:list<guanchazhe*> gcz_list;
public:void attach(guanchazhe *gcz){gcz_list.push_back(gcz);}void detech(guanchazhe *gcz){gcz_list.remove(gcz);}virtual void Notify(){list<guanchazhe*>::iterator it;for(it = gcz_list.begin();it != gcz_list.end();it++){guanchazhe *gcz = (guanchazhe *)*it;gcz->update();}}
};class laoban:public tongzhizhe
{
public:virtual void Notify(){cout << "我是老板" << endl;tongzhizhe::Notify();}
};class mishu:public tongzhizhe
{
public:virtual void Notify(){cout << "我是秘书" << endl;tongzhizhe::Notify();}
};int main(void)
{tongzhizhe *t1 = new laoban();tongzhizhe *t2 = new mishu();xiaozhang *xz = new xiaozhang();xiaowang *xw = new xiaowang();t1->attach(xz);t1->attach(xw);t1->Notify();t2->attach(xz);t2->attach(xw);t2->Notify();return 0;
}

 运行结果:

我是老板
小张收到
小王收到
我是秘书
小张收到
小王收到

二 观察者模式

我不是很喜欢这种命名,不够直观,不利于思路整理,初学还是guanchazhe,tongzhizhe这种看似很土,但是却比较容易理清思路。

观察者模式(Observer)结构图

 在上面测试中,类tongzhizhe对应Subject.
类guanchazhe对应Observer.
类laoban和xiaowang对应ConcreteSubject
类mishu和xiaowang对应ConcreteObserver.

测试代码略

三 使用函数指针模拟委托功能探讨

看书上委托的定义

 用C++来实现这两张图中的Update

1 .定义一个类叫EventHandler

2.在EventHandler中重载+运算中

3.定义个函数指针类型

4.在EventHandler定义一个链表。

聪明的你已经猜出该怎么做了吧

代码实现如下所示,写的时候发现对象的成员函数是不能直接赋值给指针的。

假设:xz.quchifan可以赋值给p1,那么p1()执行后,

cout << this->name <<  "去吃饭" << endl;

 这条代码被执行,因为没有对象调用,所示this为空this->name 使用空指针调用,段错误

证明:非静态函数不能赋值给指针。

使用函数指针实现委托的计划破产。但是从中还是可以学习C++的函数指针,重载的灵活用法。

#include <iostream>
#include <list>
using namespace std;typedef void (*update_pointer)(void);class xiaozhang{
public:string name;void quchifan(void)//去吃饭{cout << this->name <<  "去吃饭" << endl;}
};class baoan
{
public:static void quxunluo(void)//去巡逻{cout << "去巡逻" << endl;}
};class EventHandler{
public:EventHandler(){}EventHandler& operator+(update_pointer p){func_list.push_back(p);return *this;}list<update_pointer> func_list;void execute(){list<update_pointer>::iterator it;for(it = func_list.begin();it != func_list.end();it++){(*it)();}}};class tongzhizhe{
public:EventHandler update;tongzhizhe(){//update = new EventHandler();}};
int main(void)
{tongzhizhe *t = new tongzhizhe();xiaozhang xz;//update_pointer p1 = (update_pointer)(xz.quchifan);baoan ba;t->update = (t->update) + (update_pointer)(ba.quxunluo);t->update.execute();return 0;
}

运行结果:

去巡逻

小结

http://www.yayakq.cn/news/743943/

相关文章:

  • 公司备案查询网站备案学校网站建设培训心得体会
  • 实验室网站建设方案做出网站
  • 网上书店网站开发在那个网站做付汇的延期说明
  • 网站由那些组成wordpress手动主题
  • 洪江市网站wordpress 主页图片
  • 网站建设难学吗湘西做网站
  • 专业建网站服务门户网站建设会议纪要
  • 网站规划与建设 试卷wordpress建站 百度网盘
  • 合肥网站建设求职简历织梦网站内容管理系统
  • 网站制作基本流程静态网页模板制作工具
  • 做网站设计的公司有哪些上海网站推广优化
  • 河南信合建设投资集团有限公司网站无货源网店怎么开
  • 软文网站发布平台电商运营培训课程
  • 个人网站建设第一步如何建设一个门户网站
  • 网站编程电子书湖北建设网站首页
  • 男男做h的视频网站工信部公布网站备案拍照背景
  • 手机网站html声明网站打开很慢
  • 中国铁建商城电子商务平台wordpress 深度优化
  • 软件app开发定制北京空间优化平台
  • 百度收录网站标题工程平台公司是什么意思
  • 手机可以建网站吗优化网页设计是什么
  • 深圳专业商城网站有哪些文本封面做的好的网站
  • 做外贸网站要多少钱asp.net网站开发代码
  • 怎么提交网站地图盐城网站优化推广工作室
  • 网站设计代做淮安网站建设报价
  • 黄骅做网站价格网站建设 月光博客
  • 做外贸一般上哪些网站众筹网站怎么做推广
  • 网络推广网站怎么做新余商城网站建设
  • 网站怎么做微博认证最新电子产品网站模板
  • 佛山做网站费用中国房地产网站