您的位置:首页 > 编程语言 > C语言/C++

c++对象适配器

2015-10-03 17:04 411 查看
// ConsoleApplication1.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include <iostream>

//#include "Factory.h"

using namespace std;

class Target

{

public:

virtual void Request()

{

cout<<"this is the target's request"<<endl;

}

};

class Adaptee

{

public:

void SpecialRequest()

{

cout<<"this is the specialRequest"<<endl;

}

};

class Adapter:public Target

{

public:

Adapter():m_pAdaptee(new Adaptee) {}

~Adapter()

{

if(m_pAdaptee != NULL)

{

delete m_pAdaptee;

m_pAdaptee = 0;

}

}

void Request()

{

m_pAdaptee->SpecialRequest();

}

protected:

Adaptee* m_pAdaptee;

};

int _tmain(int argc, _TCHAR* argv[])

{

Target* pTarget = new Adapter;

pTarget->Request();

delete pTarget;

getchar();

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: