#include
#include
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
Array
{
m_iSize = size;
m_iLength = 0;
m_pArr = new T[m_iSize];
}
template
void Array
{
for (int i = 0; i < m_iLength; i++)
{
cout << m_pArr[i] << endl;
}
}
template
bool Array
{
if (m_iLength >= m_iSize)
{
return false;
}
m_pArr[m_iLength]=elem;
m_iLength++;
return true;
}
main(){
Array
arr1.push(1);
arr1.push(2);
arr1.push(3.3);
arr1.push(4.4);
arr1.display();
cout<<"------------"<
Array
arr2->push(1.1);
arr2->push(2.2);
arr2->display();
system("pause") ;
return 0;
}