码迷,mamicode.com
首页 > 编程语言 > 详细

C++设计模式之职责链模式

时间:2018-07-12 20:19:07      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:char*   style   ret   定义   string   mon   out   eal   ++   

代码实现:

// chainResbonsibility.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;


class Manager
{
protected:
    Manager *m_manager;
    string m_name;
public:
    Manager(Manager* manager,string name):m_manager(manager),m_name(name){}
    virtual void DealWithRequest(string name, int num) {}
};

class CommonManager : public Manager
{
public:
    CommonManager(Manager* manager,string name):Manager(manager,name){}
    void DealWithRequest(string name,int num)
    {
        if(num < 500)
        {
            cout << "经理" <<m_name << "批准" << name << "加薪" << num << "" <<endl;
        }
        else
        {
            cout << "经理" << m_name <<