//Proxy.h #ifndef AFX_CLASS_SUBJECT #define AFX_CLASS_SUBJECT class IGiveGift { public: virtual void GiveDolls() = 0; virtual void GiveFlowers() = 0; virtual void GiveChocolate() = 0; }; #endif #ifndef AFX_CLASS_REALSUBJECT #define AFX_CLASS_REALSUBJECT class Pursuit:public IGiveGift { public: Pursuit( string name ) { this->name = name; } virtual void GiveDolls() { cout<< name << " 送你洋娃娃 " <<endl; } virtual void GiveFlowers() { cout<< name << "送你鲜花" <<endl; } virtual void GiveChocolate() { cout<< name << "送你巧克力" << endl; } private: string name; }; #endif #ifndef AFX_CLASS_PROXY #define AFX_CLASS_PROXY class Proxy:public IGiveGift { public: Proxy( string mm ) { gg = new Pursuit( mm ); } void GiveDolls() { gg->GiveDolls(); } void GiveFlowers() { gg->GiveFlowers(); } void GiveChocolate() { gg->GiveChocolate(); } private: Pursuit *gg; }; #endif #include <iostream> #include <string> #include <conio.h> using namespace std; #include "proxy.h" int main( int argc ,char *argv[] ) { Proxy *daili = new Proxy( "李娇娇" ); daili->GiveDolls(); daili->GiveFlowers(); daili->GiveChocolate(); getch(); return 1; }