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;
}
//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;
}
相关文章推荐
- 项目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
- Effective C++ 18-23
- C++中cin、cin.get()、cin.getline()、getline()、gets()、cin.ignore()函数详解
- C++学习(二)-继承与派生(1)
- c++的引用(二)