标签:
#include <iostream> #include <string> using namespace std; typedef struct _ShoolGirl { string name; } ShoolGirl; /* 公共接口 */ class GiveGift { virtual void GiveDolls() = 0; virtual void GiveFlowers() = 0; virtual void GiveChocolate() = 0; }; /* 实际操作类 */ class Pursuit: public GiveGift { public: ShoolGirl *m_mm; public: Pursuit(): m_mm(NULL) {} Pursuit(ShoolGirl *mm): m_mm(mm) {} void GiveDolls(); void GiveFlowers(); void GiveChocolate(); }; void Pursuit::GiveDolls() { cout<<m_mm->name<<" give dolls!"<<endl; } void Pursuit::GiveFlowers() { cout<<m_mm->name<<" give flowers!"<<endl; } void Pursuit::GiveChocolate() { cout<<m_mm->name<<" give chocolate!"<<endl; } /* 代理类 */ class Proxy: public GiveGift { public: Pursuit *m_gg; public: Proxy(): m_gg(NULL) {} Proxy(ShoolGirl *mm); ~Proxy(); void GiveDolls(); void GiveFlowers(); void GiveChocolate(); }; Proxy::Proxy(ShoolGirl *mm) { m_gg = new Pursuit(mm); } Proxy::~Proxy() { if (m_gg) { delete m_gg; } } void Proxy::GiveDolls() { m_gg->GiveDolls(); } void Proxy::GiveFlowers() { m_gg->GiveFlowers(); } void Proxy::GiveChocolate() { m_gg->GiveChocolate(); } /* 测试 */ void main() { ShoolGirl mm; mm.name = "Girl"; Proxy proxy(&mm); proxy.GiveDolls(); proxy.GiveFlowers(); proxy.GiveChocolate(); system("pause"); }
标签:
原文地址:http://www.cnblogs.com/hushpa/p/4431504.html