array.h

来自「字符频度统计」· C头文件 代码 · 共 41 行

H
41
字号
#ifndef ARRAY_CLASS
#define ARRAY_CLASS

#include <assert.h>

template <class T>
class Array
{
private:
	T *pList;
	int nSize;

public:
	Array(int size=50)
	{
		assert(size>0);
		nSize=size;
		pList=new T[nSize];
		assert(pList!=NULL);
	}

	~Array()
	{
		delete []pList;
		nSize=0;
	}

	T & operator[](int index)
	{
		assert(index>=0&&index<nSize);
		return pList[index];
	}

	T & operator[](int index) const
	{
		assert(index>=0&&index<nSize);
		return pList[index];
	}
};

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?