vc++课程设计,求高手帮忙~

来源:百度知道 编辑:UC知道 时间:2024/06/08 03:54:52
数组的类模板设计之:
实现功能GetSize ()设置数组大小 、RemoveAll()清除数组所有元素

#include <iostream>
using std::cout;
using std::endl;

template<class T>
class CTest
{
public:
CTest(int iCapacity = 1);
~CTest();
int Size() const; //当前元素个数
void PushBack(T t);
void Print() const;
int Capacity() const; //当前容量大小
void SetSize(int iCapacity); //设置容量大小
void RemoveAll(); //清空所有元素
private:
T *m_pData;
int m_iSize;
int m_iCapacity;
};

template<class T>
CTest<T>::CTest(int iCapacity)
{
m_pData = new T[iCapacity];
m_iCapacity = iCapacity;
m_iSize = 0;
}

template<class T>
CTest<T>::~CTest()
{
delete []m_pData;
m_pData = NULL;
m_iSize = m_iCapacity = 0;
}

template<class T>
CTest<T>::Capacity() const
{
return m_iCapacity;
}

template<class T>
CTest<T&