适配器模式(C++)

#include <iostream>
using namespace std;

class USA_bolt
{
public:
    USA_bolt(){}
    ~USA_bolt(){}
    void insert(){cout<<"insert"<<endl;}
};

class target
{
public:
    target(){}
    virtual ~target(){}
    virtual void charu()=0;
};

class China_outlet_adapter : public target
{
public:
    China_outlet_adapter(){}
    virtual ~China_outlet_adapter(){}
    void charu(){_instance->insert();}

private:
    USA_bolt *_instance;
};

int main()
{
    target *p=new China_outlet_adapter;
    p->charu();
    delete p;

    system("pause");
    return 0;
}
posted @ 2012-06-25 12:18  Dsp Tian  阅读(427)  评论(0编辑  收藏  举报