原网址:https://blog.csdn.net/CoderAldrich/article/details/83115299
#include <iostream> using namespace std; class Target { public: Target() {} virtual ~Target() {} virtual void Request() { cout << "Target::Requeast"<<endl; } }; class Adaptee { public: void SpecificRequest() { cout << "Adaptee::SpecificRequest" << endl; } }; class Adapter : public Target { public: Adapter() : adaptee_(new Adaptee) {} ~Adapter() { if (adaptee_ != NULL) { delete adaptee_; adaptee_ = NULL; } } void Request() { adaptee_->SpecificRequest(); } private: Adaptee *adaptee_; }; int main() { Target *target = new Adapter(); target->Request(); delete target; target = NULL; return 0; } 输出结果: Adaptee::SpecificRequest