适配器模式(C++)

#include 
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;
}

转载于:https://www.cnblogs.com/tiandsp/archive/2012/06/25/2561021.html

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