#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;
}
//Cordiante.h
class Coordinate {
friend ostream& operator<<(ostream &out, Coordinate &coor);
public:
Coordinate(int x = 0, int y = 0);
private:
int m_iX;
int m_iY;
};
Coordinate::Coordinate(int x , int y )// 不能写(int x = 0, int y = 0)
{
m_iX = x;
m_iY = y;
}
ostream &operator<<(ostream &out, Coordinate &coor)
{
out << coor.m_iX << "," << coor.m_iY << endl;
return out;
}
main(){
Array<Coordinate, 10> arr3;
Coordinate coor1(3,5);
Coordinate coor2(2,8);
arr3.push(coor1);
arr3.push(coor2);
arr3.display();
system("pause") ;
return 0;
}