国产探花免费观看_亚洲丰满少妇自慰呻吟_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++程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 保定市| 安阳市| 凤庆县| 龙山县| 永济市| 周宁县| 堆龙德庆县| 海丰县| 株洲市| 岳西县| 台湾省| 绥江县| 贵州省| 肇庆市| 蓝山县| 清流县| 麻阳| 洪湖市| 安康市| 铁岭市| 岚皋县| 公主岭市| 连江县| 桑植县| 神木县| 宣化县| 涪陵区| 永年县| 阿图什市| 安陆市| 红桥区| 平邑县| 上饶县| 攀枝花市| 和田县| 宁海县| 宣威市| 临汾市| 赤峰市| 平潭县| 红桥区|