国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C++ > 正文

C++模板類的用法

2020-05-23 14:20:15
字體:
來源:轉載
供稿:網友

template<class T>  
void actioncontainer<T>::add(T value)  
{  
    if (m_nUndoPos >= ACTION_SIZE)  
    {  
        //如果容器已潢,剛調整添加位置  
        m_nUndoPos = ACTION_SIZE - 1;  
        for(int i = 0; i < ACTION_SIZE; i++)  
        {  
            m_UndoAction[i] = m_UndoAction[i+1];  
        }  
    }  
    m_UndoAction[m_nUndoPos++] = value;  
}  
  
template<class T>  
T actioncontainer<T>::redo()  
{  
    //將恢復動作復制到撤銷數組中  
    m_UndoAction[m_nUndoPos++] = m_RedoAction[--m_nRedoPos];  
  
    //返回恢復的動作  
    return m_RedoAction[m_nRedoPos];  
}  
  
template<class T>  
T actioncontainer<T>::undo()  
{  
    m_RedoAction[m_nRedoPos++] = m_UndoAction[--m_nUndoPos];  
  
    return m_UndoAction[m_nUndoPos];  
}

 

main.cpp源文件如下:

 

復制代碼代碼如下:
// test_iostream.cpp : 定義控制臺應用程序的入口點。  
//  
#include "StdAfx.h"  
#include "main.h"  
using namespace std;  
  
int _tmain(int argc, _TCHAR* argv[])  
{  
    actioncontainer<int> intaction;  
  
    //向容器中加動作  
    intaction.add(1);  
    intaction.add(2);  
    intaction.add(3);  
    intaction.add(4);  
  
    //撤銷上一步動作  
    int nUndo = intaction.undo();  
    nUndo = intaction.undo();  
  
    //恢復  
    int nRedo = intaction.redo();  
    return 0;  
}

 

希望本文所述對大家的C++程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 彭山县| 岳普湖县| 温泉县| 大关县| 彭山县| 北川| 通江县| 天峨县| 红原县| 温泉县| 敦煌市| 墨江| 海口市| 孝昌县| 海南省| 宁津县| 买车| 汤原县| 嘉荫县| 卓尼县| 南雄市| 乌什县| 罗甸县| 青川县| 历史| 六枝特区| 嵊泗县| 龙海市| 鄯善县| 东方市| 二连浩特市| 大关县| 泽库县| 方城县| 五寨县| 三河市| 图片| 屏南县| 化州市| 集贤县| 岳阳市|