#include "stdafx.h" #include <iostream> using namespace std; // 定义女人 class KindWomen{ public: virtual void MakeEyesWithMan() = 0; virtual void HappyWithMan() = 0; }; // 定义潘金莲 class PanJinLian : public KindWomen { public: virtual void MakeEyesWithMan() { cout << "潘金莲抛媚眼" << endl; } virtual void HappyWithMan() { cout << "潘金莲在和男人做那个....." << endl; } }; // 定义贾氏 class JiaShi : public KindWomen { public: virtual void MakeEyesWithMan() { cout << "贾氏抛媚眼" << endl; } virtual void HappyWithMan() { cout << "贾氏在和男人做那个....." << endl; } }; // 王婆年老色衰,不能啪啪啪了 class WangPo : public KindWomen { private: KindWomen *m_pWomen; public: WangPo() { m_pWomen = new PanJinLian(); } WangPo(KindWomen *p) { m_pWomen = p; } ~WangPo() { if (m_pWomen != nullptr) { delete m_pWomen; } } virtual void MakeEyesWithMan() { m_pWomen->MakeEyesWithMan(); } virtual void HappyWithMan() { m_pWomen->HappyWithMan(); } }; int _tmain(int argc, _TCHAR* argv[]) { cout << "西门庆色心起" << endl; cout << "王婆为西门庆和潘金莲搭桥" << endl; WangPo *p = new WangPo(); p->MakeEyesWithMan(); p->HappyWithMan(); delete p; JiaShi *pj = new JiaShi(); cout << "王婆为西门庆和贾氏搭桥" << endl; p = new WangPo(pj); p->MakeEyesWithMan(); p->HappyWithMan(); delete p; return 0; }
王婆是代理方,潘金莲和贾氏氏被代理方。