C++ Memento模式应用法则
C++编程语言中的应用方式比较灵活,我们可以通过各种模式来实现特定的功能。比如今天为大家介绍的C++ Memento模式,就是一个非常有用的应用模式,希望大家可以从中获得一些帮助。
C++ Memento模式代码示例:
#include< iostream> #include< string> using namespace std; typedef string states; class Memento; class Orininator { public: Orininator(){m_st="";m_mt=0;}; Orininator(const states& st){m_st=st;m_mt=0;}; ~Orininator(){}; Memento* CreateMemento(); void SetMemento(Memento* men){}; void RestoretoMen(Memento* mt); states GetState(){return m_st;}; void SetState(const states& sdt){m_st=sdt;} void PrintState(){cout< this->m_st< < ".."< < endl;} private: states m_st; Memento* m_mt; };
class Memento { private: friend class Orininator;//友元 Memento(){}; Memento(const states& st){m_st=st;}; ~Memento(){}; void SetState(const states& std){m_st=std;}; states GetState(){return m_st;}; private: states m_st; };
Memento* Orininator::CreateMemento() { return new Memento(m_st);//合理的应用构造函数; } void Orininator::RestoretoMen(Memento* mt) { this->m_st=mt->GetState(); }
相关推荐
文山羊 2020-11-07
susmote 2020-11-07
拉斯厄尔高福 2020-11-04
xceman 2020-10-23
hellojunz 2020-10-23
caojhuangy 2020-10-12
xinyupan 2020-09-28
lousir 2020-09-27
一个逗逗 2020-09-22
Maryhuan 2020-09-20
rkhstar 2020-09-09
DreamSnow 2020-09-09
aehousmantao 2020-09-03
tkernel 2020-09-03
abfdada 2020-08-26
svap 2020-08-25
二十不悔三十而立 2020-08-19
FlightForever 2020-08-17
joyjoy0 2020-08-13