适配器模式(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;
}

你可能感兴趣的:(适配器模式)