代码实现: //Adapter.h
#include "stdafx.h" #includeclass Adaptee { public: void Request() { std::cout << "实际要使用的类方法!" << std::endl; } }; class Target { public: virtual ~Target(){} virtual void Operator() = 0; }; class Adapter :public Target { private: Adaptee* m_Adaptee = new Adaptee(); public: virtual void Operator() { m_Adaptee->Request(); } };
// AdapterPattern.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "Adapter.h"
int _tmain(int argc, _TCHAR* argv[])
{
Target* target = new Adapter();
target->Operator();
getchar();
return 0;
}