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;
}
//
#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;
}
相关文章推荐
- 项目32.4 输出小星星
- c++面试题
- C++ "#"的作用和用法
- c++类适配器
- 项目32.3 输出小星星
- C++运算符重载
- 在VS2015中配置和测试DCMTK遇到的问题
- C语言 switch和if..else的区别 以及枚举的作用
- C++ 中STL map 详解
- C++中“浅拷贝”与“深拷贝”
- C++primer第五版笔记-第六章函数
- C/C++中四种不同的类型转换方式
- 洛谷1071 潜伏者
- 项目32.2 输出小星星
- 项目32.1输出小星星
- C++学习笔记之多态(虚函数)
- c++遍历文件夹中的图片(或文件)
- C语言 scanf()和gets()函数的区别
- struct 大小的计算
- 【C++】c++日期类Date