Qt C++ prototype(原型模式或者克隆模式)
来源:互联网 发布:免签约php发卡平台 编辑:程序博客网 时间:2024/06/05 16:41
prototype.h
#pragma once
#include <QDebug>
#include <QObject>
#include <QString>
class CProtoTypeBase
{
public:
virtual CProtoTypeBase* clone() = 0;
virtual void printAuthor() = 0;
virtual void printGroup() = 0;
void setAuthor(const QString &author){m_author = author;}
QString getAtuthor() const{return m_author;}
private:
QString m_author;
};
class CComputerBook : public CProtoTypeBase
{
public:
CComputerBook(){};
CProtoTypeBase* clone();
void printAuthor();
void printGroup();
};
class CStoryBook : public CProtoTypeBase
{
public:
CStoryBook(){};
CProtoTypeBase* clone();
void printAuthor();
void printGroup();
};
prototype.cpp
#include "prototype.h"
CProtoTypeBase* CComputerBook::clone()
{
CComputerBook *p = new CComputerBook;
*p = *this;
return p;
}
void CComputerBook::printAuthor()
{
qDebug() << "computerAuthor";
}
void CComputerBook::printGroup()
{
qDebug() << "";
}
CProtoTypeBase* CStoryBook::clone()
{
CStoryBook *p = new CStoryBook;
*p = *this;
return p;
}
void CStoryBook::printAuthor()
{
qDebug() << "storyAuthor";
}
void CStoryBook::printGroup()
{
qDebug() << "";
}
main.cpp
#include <QApplication>
#include "prototype.h"
int main(int argc,char **argv)
{
QApplication app(argc,argv);
CProtoTypeBase *computer = new CComputerBook;
computer->setAuthor("xiaojiji");
CProtoTypeBase * com2 = computer->clone();
qDebug() << com2->getAtuthor();
com2->setAuthor("xiaoniuniu");
qDebug() << com2->getAtuthor();
delete computer;
delete com2;
return app.exec();
}
- Qt C++ prototype(原型模式或者克隆模式)
- 对象的克隆--原型模式(Prototype)
- Prototype原型模式和深克隆
- 深入浅出设计模式 ------ Prototype(原型模式)之深度克隆
- 原型模式 Prototype模式
- 原型模式 Prototype模式
- 原型模式:prototype模式
- 原型模式 Prototype模式
- Prototype模式(原型模式)
- 原型模式:prototype模式
- 克隆(原型)模式
- 原型克隆模式
- 深度克隆,原型模式
- 原型模式-Prototype Pattern 对象的克隆——原型模式(一):大同小异的工作周报,原型模式概述
- 原型模式-Prototype Pattern 对象的克隆——原型模式(二):工作周报的原型模式解决方案
- Java 深复制(深克隆)&浅复制(浅克隆)&原型模式(ProtoType)
- 原型模式(Prototype)
- 原型模式(prototype)
- Linux下mysql表名不区分大小写设置
- 教大家认识unix系统的hosts文件【系统收藏:xitongshoucang】
- Java调用天气预报调用代码
- lucene--创建索引,搜索
- 关于System.arraycopy()的实现
- Qt C++ prototype(原型模式或者克隆模式)
- HDU3306(科波菲尔数列+快速幂)
- 上篇日本人经营之道 一制造轰动效应出奇制胜
- Redis总结
- Mysql帐号远程登陆时 ERROR 1130 的解决办法
- 破解软件的思路
- 总结运算符重载的方法
- git使用说明
- JVM调优总结