#include <ostream>
#include <iostream>
using namespace std;
//Array.h
template <typename T, int size>
class Array{
public:
Array(); // 也算是默认构造函数,因为不需要传进去参数
bool push(T elem);
void display();
private:
T *m_pArr;
int m_iSize;
int m_iLength;
};
template <typename T, int size>
Array<T,size>::Array ()
{
m_iSize = size;
m_iLength = 0;
m_pArr = new T[m_iSize];
}
template <typename T, int size>
void Array<T,size>::display()
{
for (int i = 0; i < m_iLength; i++)
{
cout << m_pArr[i] << endl;
}
}
template<typename T, int size>
bool Array<T,size>::push(T elem)
{
if (m_iLength >= m_iSize)
{
return false;
}
m_pArr[m_iLength]=elem;
m_iLength++;
return true;
}
main(){
Array<int, 10> arr1;
arr1.push(1);
arr1.push(2);
arr1.push(3.3);
arr1.push(4.4);
arr1.display();
cout<<"------------"<<endl;
Array<double,10> *arr2 = new Array <double,10>;// new Array <double,10>(); 也可以
arr2->push(1.1);
arr2->push(2.2);
arr2->display();
system("pause") ;
return 0;
}