您的位置:首页 > 其它

C适配器

2016-03-30 23:57 253 查看
/**************************
WZ ASUST  2016
(1)
C++ primer中
关于适配器的定义——适配器(adaptor):
是使一种事物的行为
类似于另外一事物的行为的一种机制。
(2)
类间需要互相传递参数,但是接口类型不相同,
中间加上适配器就能起转换操作的作用。
(3)
STL定义了3种形式的适配器:
函数适配器
容器适配器
迭代器适配器
**************************/
#include"wz.h"
#include"sts.h"
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  main( )
{
Target* pTarget = new Adapter;
pTarget->Request();
delete pTarget;
getchar();
return 0;
}
/*************
main测试
用Adaptr 生成一对象  并以父类 Target 的pTarget指针指向这一块空间
再访问原有的R函数 发生了变化
被改写
************/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c适配器