📄 array.h
字号:
#ifndef ARRAY_CLASS
#define ARRAY_CLASS
#include <iostream.h>
#include <stdlib.h>
const DefaultSize=100;
template <class T>
class Array
{
public:
Array(int size=DefaultSize);
~Array(){delete []elements;}
T & operator [](int i);
private:
T *elements;
int ArraySize;
void GetArray();
};
template <class T>
void Array<T>::GetArray()
{
elements=new T[ArraySize];
if(elements==0)
{
cout<<"Memory Allocation Error!"<<endl;
ArraySize=0;
return;
}
}
template <class T>
Array<T>::Array(int sz)
{
if(sz<=0)
{
cout<<"Invalid Array Size"<<endl;
ArraySize=0;
return;
}
ArraySize=sz;
GetArray();
}
template <class T>
T & Array<T>::operator [](int i)
{
if(i<0||i>ArraySize-1)
{
cout<<"Index out of range"<<endl;
return;
}
return elements[i];
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -