c++適配器

/**************************

      WZ ASUST  2016

(1)
C++ primer中
關於適配器的定義——適配器(adaptor):
是使一種事物的行爲
類似於另外一事物的行爲的一種機制。
(2)
 類間需要互相傳遞參數,但是接口類型不相同,
  中間加上適配器就能起轉換操作的作用。
(3)
STL定義了3種形式的適配器:
               函數適配器
               容器適配器
               迭代器適配器

**************************/
#include"wz.h"
#include"sts.h"
class Target
{
  public:
  virtual void Request()
  {
  cout<<"this is the target's request"<<endl;
  }
};


class Adaptee
{
  public:
  void SpecialRequest()
  {
   cout<<"this is the specialRequest"<<endl;
  }
};


class Adapter:public Target, public Adaptee
{
  public:
  void Request()
   {
    SpecialRequest();
   }
};

int  main( )
{
Target* pTarget = new Adapter;
pTarget->Request();
delete pTarget;
getchar();
return 0;
}
/*************
 

main測試
用Adaptr 生成一對象  並以父類 Target 的pTarget指針指向這一塊空間
再訪問原有的R函數 發生了變化
被改寫
************/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章