#include "stdafx.h"
#include <iostream>
#include <string>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
using namespace boost;
#define CC_SYNTHESIZE(varType, varName, funName)\
protected: varType varName;\
public: virtual varType get##funName(void) const { return varName; }\
public: virtual void set##funName(varType var){ varName = var; }
class Prototype
{
public:
Prototype(){}
virtual ~Prototype(){}
virtual shared_ptr<Prototype> clone() const
{
return NULL;
}
CC_SYNTHESIZE(std::string,__m_strData,Data);
};
class ConcretePrototype : public Prototype
{
public:
ConcretePrototype(){}
~ConcretePrototype(){}
//拷贝构造函数
ConcretePrototype(const ConcretePrototype& prototype)
{
__m_strData = prototype.getData();
}
shared_ptr<Prototype> clone() const
{
return make_shared<Prototype>(*this);
}
};
void testPrototype()
{
shared_ptr<ConcretePrototype> ptrPrototype = make_shared<ConcretePrototype>();
ptrPrototype->setData("aaa");
auto ptr2 = ptrPrototype->clone();
std::cout << ptr2->getData() << std::endl;
}
Prototype
最新推荐文章于 2024-07-24 16:06:12 发布