template model
2016-07-23 17:21
323 查看
#include <iostream> #include <windows.h> using namespace std; /************************************************************************/ /* 模板模式:定义一个操作中的骨架,将一些延迟操作放到子类中 /* 模板模式使子类可以不改变一个算法的骨架即可重定义该算法中的某些特定的步骤 /************************************************************************/ class CalcSNR { public: CalcSNR() { } void GetSNRValue() { GetRawData(); GetBaseData(); double dSNR = StartCalcSNR(); cout << "SNR Value:" << dSNR << endl; } virtual void GetRawData() = 0; virtual void GetBaseData() = 0; virtual double StartCalcSNR() = 0; }; class SNRAlogrithm : public CalcSNR { public: virtual void GetRawData() { //throw std::logic_error("The method or operation is not implemented."); cout << "Get Raw Data"<<endl; } virtual void GetBaseData() { ///throw std::logic_error("The method or operation is not implemented."); cout << "Get Base Data"<<endl; } virtual double StartCalcSNR() { //throw std::logic_error("The method or operation is not implemented."); cout << "Start Calc SNR"<<endl; return 0.1; } }; int main(int argc, char *argv[]) { CalcSNR *pCalcSNR = new SNRAlogrithm(); pCalcSNR->GetSNRValue(); getchar(); }
相关文章推荐
- Java进阶(三十七)java 自动装箱与拆箱
- iOS应用文件夹
- 字节序不是由操作系统决定的,而是由cpu架构决定的
- java中序列化之子类继承父类序列化
- 【HDU】2588 - GCD(欧拉函数)
- [gdc16]《星球大战:前线》的美术制作技术
- 2016夏季练习——最小生成树
- poll 机制
- 摘自:javascript的理解DOM事件流的三个阶段
- error: 'retain' is unavailable: not available in automatic reference counting
- 字符串匹配优化(KMP)(写+转载)
- Managing Processes and Threads in Windows Forms
- PHP导出word文档的简单实现方法(可导出图片)
- poj 3641 Pseudoprime numbers
- [干货] Flume综述与实例
- 2012杭州赛区(浙江理工大学)J - Scaring the Birds
- Windows下的PHP开发环境配置及常见问题解决
- Activity中使用注解进行状态保存
- 吃豆人,一个小游戏,使用第三方图形库EasyX
- hdu 3666(差分约束,手动栈解决超时问题)