新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C++Memento模式應(yīng)用法則
C++編程語言中的應(yīng)用方式比較靈活,我們可以通過各種模式來實現(xiàn)特定的功能。比如今天為大家介紹的C++ Memento模式,就是一個非常有用的應(yīng)用模式,希望大家可以從中獲得一些幫助。

創(chuàng)新互聯(lián)是專業(yè)的雞西網(wǎng)站建設(shè)公司,雞西接單;提供做網(wǎng)站、成都網(wǎng)站設(shè)計,網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進行雞西網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!
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();
- }
以上就是對C++ Memento模式的相關(guān)介紹。
當前題目:C++Memento模式應(yīng)用法則
新聞來源:http://www.5511xx.com/article/cdeisgh.html


咨詢
建站咨詢
