#include <iostream> using namespace std; class PC_Game{ public: virtual void play(){ cout<<"0/n";} }; class PC_SanGuo :public PC_Game{ public: void play(){ cout<<"单机版三国游戏/n";} }; class PC_CS :public PC_Game{ public: void play(){ cout<<"单机版CS游戏/n";} }; ///////////////////////////////////////////////// class WEB_Game{ public: virtual void play(){ cout<<"0/n";} }; class WEB_SanGuo :public WEB_Game{ public: void play(){ cout<<"网络版三国游戏/n";} }; class WEB_CS :public WEB_Game{ public: void play(){ cout<<"网络版CS游戏/n";} }; /////////////////////////////////////////////////// class company{ public: virtual PC_Game* creatPC_Game()=0; virtual WEB_Game* creatWEB_Game()=0; }; class company_C :public company{ public: PC_Game* creatPC_Game(){ return new PC_SanGuo;} WEB_Game* creatWEB_Game(){ return new WEB_SanGuo;} }; class company_D :public company{ public: PC_Game* creatPC_Game(){ return new PC_CS;} WEB_Game* creatWEB_Game(){ return new WEB_CS;} }; ///////////////////////////////////////////////////// class Saler_A{ PC_Game *sanguo,*cs; public: Saler_A(PC_Game *s,PC_Game *c) :sanguo(s),cs(c) {} void product() { cout<<"我公司销售:/n"; sanguo->play(); cs->play(); } }; class Saler_B{ WEB_Game *sanguo, *cs; public: Saler_B( WEB_Game *s,WEB_Game *c) :sanguo(s),cs(c) {} void product() { cout<<"我公司销售:/n"; sanguo->play(); cs->play(); } }; /////////////主函数////////////////////////// void main() { company *comC,*comD; comC = new company_C; comD = new company_D; PC_Game *PCsanguo,*PCcs; PCsanguo = comC->creatPC_Game(); PCcs = comD->creatPC_Game(); WEB_Game *WEBsanguo,*WEBcs; WEBsanguo = comC->creatWEB_Game(); WEBcs = comD->creatWEB_Game(); Saler_A salerA(PCsanguo,PCcs); salerA.product(); Saler_B salerB(WEBsanguo,WEBcs); salerB.product(); delete PCsanguo; delete PCcs; delete WEBsanguo; delete WEBcs; delete comC; delete comD; }