程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> ´ó»°Éè¼ÆģʽC++ʵÏÖ-µÚ17ÕÂ-ÊÊÅäÆ÷ģʽ

´ó»°Éè¼ÆģʽC++ʵÏÖ-µÚ17ÕÂ-ÊÊÅäÆ÷ģʽ

編輯:C++入門知識

´ó»°Éè¼ÆģʽC++ʵÏÖ-µÚ17ÕÂ-ÊÊÅäÆ÷ģʽ


Ò»¡¢UMLͼ

\


¶þ¡¢¸ÅÄî

ÊÊÅäÆ÷ģʽ£º<†·Ÿ"http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vc3Ryb25nPr2r0ru49sDgtcS907/a16q7u7PJv827p8+jzfu1xMHtzeLSu7j2vdO/2qGjQWRhcHRlcsSjyr3KubXD1K3AtNPJ09q907/asru85sjdtviyu8Tc0rvG8Lmk1/e1xMTH0KnA4L/J0tTSu8bwuaTX96GjPC9wPgo8cD48YnI+CjwvcD4KPHA+PHN0cm9uZz7I/aGiy7XD9zwvc3Ryb25nPjwvcD4KPHA+PHN0cm9uZz69x8mro7o8L3N0cm9uZz48L3A+CjxwPqOoMaOpVGFyZ2V0o7rV4srHv827p8v5xtq0/bXEvdO/2qOsVGFyZ2V0v8nS1MrHvt/M5bXEu/Kz6c/ztcTA4KOs0rK/ydLUyse907/aoaM8L3A+CjxwPqOoMqOpQWRhcHRlZaO60OjSqsrKxeS1xMDgoaM8L3A+CjxwPqOoM6OpQWRhcHRlcqO6zai5/dTaxNqyv7D817DSu7j2QWRhcHRlZbbUz/OjrLDR1LS907/a16q7u7PJxL+x6r3Tv9qhozwvcD4KPHA+PHN0cm9uZz7KssO0yrG68tPDo788L3N0cm9uZz48L3A+CjxwPqOoMaOp1NrP68q508PSu7j20tG05tTatcTA4KOstavKx8jnufvL+7XEvdO/2qOs0rK+zcrHy/y1xLe9t6i6zcTjtcTSqsfzsrvP4M2syrGjrL7N06a4w7+8wsfTw8rKxeTG98Sjyr2hozwvcD4KPHA+o6gyo6nTw8HLysrF5Mb3xKPKvaOsv827p7T6wuu/ydLUzbPSu7X308PNs9K7vdO/2r7N0NDBy6Os1eLR+b/J0tS4/LzytaWjrLj81rG906OsuPy99LTVoaM8L3A+CjxwPqOoM6Op0qrU2surt722vLK7zKvI3dLX0N64xLXEyrG68tTZyrnTw8rKxeTG98Sjyr3KysXko6y2+LK7ysfSu9PQsrvNrMrHvs3KudPDy/yhozwvcD4KPHA+PHN0cm9uZz48YnI+Cjwvc3Ryb25nPjwvcD4KPHA+PHN0cm9uZz7LxKGiQyYjNDM7JiM0MzvKtc/WPC9zdHJvbmc+PC9wPgo8cD6jqDGjqUFkYXB0ZXIuaDwvcD4KPHA+PC9wPgo8cHJlIGNsYXNzPQ=="brush:java;">#ifndef ADAPTER_H #define ADAPTER_H #include #include //Target,´Ë´¦ÎªÔ˶¯Ô± class Player { protected: std::string name; public: Player(std::string name) { this->name=name; } virtual void Attack()=0; virtual void Defense()=0; }; //Adaptee£¬´Ë´¦ÎªÍâ¼®Öз棬ËüµÄ½Ó¿ÚºÍTargetµÄ½Ó¿Ú²»Ò»Ñù£¬ÐèÒª·­ÒëÀ´°ïæת»» class ForeignCenter { private: std::string name; public: void SetName(std::string name) { this->name=name; } std::string GetName() { return name; } void ForeignAttack() { std::cout<<"Íâ¼®Öзæ "<SetName(name); } ~Translator() { delete wjzf; } void Attack() { wjzf->ForeignAttack(); } void Defense() { wjzf->ForeignDefense(); } }; //ÏÂÃæÊÇÆÕͨµÄ ½Ó¿ÚºÍTarget½Ó¿ÚÒ»ÑùµÄ 3¸ö×ÓÀ࣬±ØÐëÒª·­Òë //Ç°·æ class Forwards:public Player { public: Forwards(std::string name):Player(name){} void Attack() { std::cout<<"Ç°·æ "<

£¨2£©Client.cpp

#include "Adapter.h"
#include 
#include 
#include 

//Client
void main()
{
	Player* b=new Forwards("°ÍµÙ¶û");
	b->Attack();

	Player* m=new Guards("Âó¿Ë¸ñÀ×µÏ");
	m->Attack();

	//·­Òë¸æËßÒ¦Ã÷£¬½ÌÁ·ÈÃÄã¼ÈÒª½ø¹¥£¬ÓÖÒª·ÀÊØ
	Player* ym=new Translator("Ò¦Ã÷");
	ym->Attack();
	ym->Defense();

	delete b;
	delete m;
	delete ym;

	system("pause");
}


£¨3£©ÔËÐнØͼ



  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved