代码如下:
#include <iostream>
#include <string>
using namespace std;
class manager
{
protected:
manager *m_manager;
string m_name;
public:
manager(manager *n_manager, string name):m_manager(n_manager),m_name(name) {}
virtual void dowithrequest(string name, int num) {}
};
class cmanager: public manager
{
public:
cmanager(manager *n_manager, string name):manager(n_manager,name) {}
void dowithrequest(string name, int num)
{
if (num < 100)
{
cout<<"经理"<<m_name<<"同意"<<name<<"加工资"<<num<<""<<endl;
}
else
{
cout<<"经理"<<m_name<<"没有权限,给总经理处理"<<endl;
m_manager->dowithrequest(name, num);
}
}
};
class gmanager: public manager
{
public:
gmanager(manager *n_manager, string name):manager(n_manager,name) {}
void dowithrequest(string name, int num)
{
cout<<"总经理"<<m_name<<"同意"<<name<<"加工资"<<num<<""<<endl;
}
};
int main()
{
manager *g = new gmanager(NULL, "A");
manager *c = new cmanager(g, "B");
c->dowithrequest("D",50);
c->dowithrequest("E",500);
delete c;
delete g;
return 0;
}