欢迎来到天天文库
浏览记录
ID:9879295
大小:82.50 KB
页数:11页
时间:2018-05-13
《mfc类库carray类模板源代码注释及在win32 控制台程序中的简单使用》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、2010年9月14日16:58:44新建一个Win32控制台程序,使用MFC类库。工程设置:点击菜单“Project”à“Settings”,选择“General”标签,在“MicrosoftFoundationClasses”组合框下,选择“UseMFCinaSharedDLL”。以静态链接库的形式使用MFC类库。源程序如下:#include#include#includeintmain(){CArray2、t>m_array;//定义数组对象CPointpt1(10,10);//定义对象并存放在数组中m_array.Add(pt1);CPointpt2(20,20);m_array.Add(pt2);CPointpt3(30,30);m_array.Add(pt3);intsize=m_array.GetSize();//获取数组实际大小---元素个数CPointpt;intindex=0;for(index=0;index3、(index);cout<templateclassCArray:publicCObject{public://ConstructionCArray();//4、AttributesintGetSize()const;intGetUpperBound()const;voidSetSize(intnNewSize,intnGrowBy=-1);//Operations//CleanupvoidFreeExtra();voidRemoveAll();//AccessingelementsTYPEGetAt(intnIndex)const;voidSetAt(intnIndex,ARG_TYPEnewElement);TYPE&ElementAt(intnInde5、x);//DirectAccesstotheelementdata(mayreturnNULL)constTYPE*GetData()const;TYPE*GetData();//PotentiallygrowingthearrayvoidSetAtGrow(intnIndex,ARG_TYPEnewElement);intAdd(ARG_TYPEnewElement);intAppend(constCArray&src);voidCopy(constCArray&src);//overloaded6、operatorhelpersTYPEoperator[](intnIndex)const;TYPE&operator[](intnIndex);//OperationsthatmoveelementsaroundvoidInsertAt(intnIndex,ARG_TYPEnewElement,intnCount=1);voidRemoveAt(intnIndex,intnCount=1);voidInsertAt(intnStartIndex,CArray*pNewArray);//Implem7、entationprotected:TYPE*m_pData;//theactualarrayofdata//保存实际数组的指针intm_nSize;//#ofelements(upperBound-1)//数组的元素个数intm_nMaxSize;//maxallocated//数组的容量大小intm_nGrowBy;//growamountpublic:~CArray();voidSerialize(CArchive&);#ifdef_DEBUGvoidDump(CDumpContext&)co8、nst;voidAssertValid()const;#endif};//构造函数的实现templateCArray::CArray(){//数据成员初始化,空数组m_pData=NULL;m_nSize=m_nMaxSize=m_nGrowBy=0;}typedefunsignedcharBYTE;//1个字节//析构函数的实现template
2、t>m_array;//定义数组对象CPointpt1(10,10);//定义对象并存放在数组中m_array.Add(pt1);CPointpt2(20,20);m_array.Add(pt2);CPointpt3(30,30);m_array.Add(pt3);intsize=m_array.GetSize();//获取数组实际大小---元素个数CPointpt;intindex=0;for(index=0;index3、(index);cout<templateclassCArray:publicCObject{public://ConstructionCArray();//4、AttributesintGetSize()const;intGetUpperBound()const;voidSetSize(intnNewSize,intnGrowBy=-1);//Operations//CleanupvoidFreeExtra();voidRemoveAll();//AccessingelementsTYPEGetAt(intnIndex)const;voidSetAt(intnIndex,ARG_TYPEnewElement);TYPE&ElementAt(intnInde5、x);//DirectAccesstotheelementdata(mayreturnNULL)constTYPE*GetData()const;TYPE*GetData();//PotentiallygrowingthearrayvoidSetAtGrow(intnIndex,ARG_TYPEnewElement);intAdd(ARG_TYPEnewElement);intAppend(constCArray&src);voidCopy(constCArray&src);//overloaded6、operatorhelpersTYPEoperator[](intnIndex)const;TYPE&operator[](intnIndex);//OperationsthatmoveelementsaroundvoidInsertAt(intnIndex,ARG_TYPEnewElement,intnCount=1);voidRemoveAt(intnIndex,intnCount=1);voidInsertAt(intnStartIndex,CArray*pNewArray);//Implem7、entationprotected:TYPE*m_pData;//theactualarrayofdata//保存实际数组的指针intm_nSize;//#ofelements(upperBound-1)//数组的元素个数intm_nMaxSize;//maxallocated//数组的容量大小intm_nGrowBy;//growamountpublic:~CArray();voidSerialize(CArchive&);#ifdef_DEBUGvoidDump(CDumpContext&)co8、nst;voidAssertValid()const;#endif};//构造函数的实现templateCArray::CArray(){//数据成员初始化,空数组m_pData=NULL;m_nSize=m_nMaxSize=m_nGrowBy=0;}typedefunsignedcharBYTE;//1个字节//析构函数的实现template
3、(index);cout<templateclassCArray:publicCObject{public://ConstructionCArray();//
4、AttributesintGetSize()const;intGetUpperBound()const;voidSetSize(intnNewSize,intnGrowBy=-1);//Operations//CleanupvoidFreeExtra();voidRemoveAll();//AccessingelementsTYPEGetAt(intnIndex)const;voidSetAt(intnIndex,ARG_TYPEnewElement);TYPE&ElementAt(intnInde
5、x);//DirectAccesstotheelementdata(mayreturnNULL)constTYPE*GetData()const;TYPE*GetData();//PotentiallygrowingthearrayvoidSetAtGrow(intnIndex,ARG_TYPEnewElement);intAdd(ARG_TYPEnewElement);intAppend(constCArray&src);voidCopy(constCArray&src);//overloaded
6、operatorhelpersTYPEoperator[](intnIndex)const;TYPE&operator[](intnIndex);//OperationsthatmoveelementsaroundvoidInsertAt(intnIndex,ARG_TYPEnewElement,intnCount=1);voidRemoveAt(intnIndex,intnCount=1);voidInsertAt(intnStartIndex,CArray*pNewArray);//Implem
7、entationprotected:TYPE*m_pData;//theactualarrayofdata//保存实际数组的指针intm_nSize;//#ofelements(upperBound-1)//数组的元素个数intm_nMaxSize;//maxallocated//数组的容量大小intm_nGrowBy;//growamountpublic:~CArray();voidSerialize(CArchive&);#ifdef_DEBUGvoidDump(CDumpContext&)co
8、nst;voidAssertValid()const;#endif};//构造函数的实现templateCArray::CArray(){//数据成员初始化,空数组m_pData=NULL;m_nSize=m_nMaxSize=m_nGrowBy=0;}typedefunsignedcharBYTE;//1个字节//析构函数的实现template
此文档下载收益归作者所有