首页 > 其他 > 详细

递归思想(一)

时间:2014-03-03 16:58:56      阅读:176      评论:0      收藏:0      [点我收藏+]

Prototype模式通过复制原型(Prototype)而获得新对象创建的功能,这里Prototype本身就是“对象工厂”

prototype.h:

#ifndef _PROTOTYPE_H_
#define _PROTOTYPE_H_

class Prototype
{
public:
	virtual ~Prototype();
	virtual Prototype* Clone() const = 0;
protected:
	Prototype();
private:
};

class ConcretePrototype:public Prototype
{
public:
	ConcretePrototype();
	ConcretePrototype(const ConcretePrototype& cp);
	~ConcretePrototype();
	Prototype* Clone() const;
protected:
private:
};
#endif //~_PROTOTYPE_H_
prototype.cpp:

#include "prototype.h"
#include <iostream>
using namespace std;


Prototype::Prototype(){

}
Prototype::~Prototype(){

}
Prototype* Prototype::Clone() const{

	return 0;
}


ConcretePrototype::ConcretePrototype(){

}
ConcretePrototype::~ConcretePrototype(){

}
ConcretePrototype::ConcretePrototype(const ConcretePrototype& cp){

	cout<<"ConcretePrototype copy ..."<<endl;
}
Prototype* ConcretePrototype::Clone() const{

	return new ConcretePrototype(*this);
}
main.cpp:

#include "prototype.h"

#include <iostream>
using namespace std;


int main(){

	Prototype* p = new ConcretePrototype();
	Prototype* p1 = p->Clone();

	return 1;
}




递归思想(一),布布扣,bubuko.com

递归思想(一)

原文:http://blog.csdn.net/u012333003/article/details/20284555

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!