C++中如何應(yīng)用Memento模式-創(chuàng)新互聯(lián)

這篇文章主要介紹“C++中如何應(yīng)用Memento模式”的相關(guān)知識(shí),小編通過實(shí)際案例向大家展示操作過程,操作方法簡單快捷,實(shí)用性強(qiáng),希望這篇“C++中如何應(yīng)用Memento模式”文章能幫助大家解決問題。

站在用戶的角度思考問題,與客戶深入溝通,找到武勝網(wǎng)站設(shè)計(jì)與武勝網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都做網(wǎng)站、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、申請(qǐng)域名、虛擬空間、企業(yè)郵箱。業(yè)務(wù)覆蓋武勝地區(qū)。

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);//合理的應(yīng)用構(gòu)造函數(shù);  }  void Orininator::RestoretoMen(Memento* mt)  {  this->m_st=mt->GetState();  }
void main()  {  Orininator* Ori=new Orininator();  Ori->SetState("old");  Ori->PrintState();  Memento* m=Ori->CreateMemento();  Ori->SetState("new");  Ori->PrintState();  Ori->RestoretoMen(m);  Ori->PrintState();  }

關(guān)于“C++中如何應(yīng)用Memento模式”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí),可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,小編每天都會(huì)為大家更新不同的知識(shí)點(diǎn)。

新聞標(biāo)題:C++中如何應(yīng)用Memento模式-創(chuàng)新互聯(lián)
當(dāng)前URL:http://muchs.cn/article4/dpjcie.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開發(fā)、網(wǎng)站策劃、品牌網(wǎng)站制作、關(guān)鍵詞優(yōu)化、面包屑導(dǎo)航、網(wǎng)站設(shè)計(jì)公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化