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

c++类适配器

2015-10-03 16:57 295 查看
// ConsoleApplication1.cpp : Defines the entry point for the console application.

//Target生成对象是合理的,so不用纯虚函数

#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 Adaptee

{

public:

void Request()

{

SpecialRequest();

}

};

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

{

Target* pTarget = new Adapter;

pTarget->Request();

delete pTarget;

getchar();

return 0;

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