帮我看下这个程序。说链接错误。
这是Array.H头文件:#ifndef ARRAY_H
#define ARRAY_H
#include <iostream>
using namespace std;
template <typename elemType>
class Array
{
public:
Array(elemType *, int);
~Array();
elemType &operator [](int) const;
void display() const;
friend ostream &operator <<(ostream &, const Array &);
private:
int _size;
elemType *pArray;
};
template <typename elemType>
inline Array<elemType>::Array(elemType *elem, int size):
_size(size)
{
pArray = new elemType[_size];
for(int ix=0;ix<_size;++ix)
{
pArray[ix] = elem[ix];
}
}
template <typename elemType>
inline Array<elemType>::~Array()
{
delete [] pArray;
}
template <typename elemType>
inline elemType &Array<elemType>::operator [](int offset) const
{
if(offset >= _size)
{
cout << "数组越界!" << endl;
exit(-1);
}
else
return pArray[offset];
}
template <typename elemType>
inline void Array<elemType>::display() const
{
for(int ix=0;ix<_size;++ix)
cout << pArray[ix] << " ";
cout << endl;
}
#endif
这是Array.cpp源文件:
#include "Array.h"
#include <iostream>
using namespace std;
template <typename elemType>
ostream &operator <<(ostream &os, const Array<elemType> &theArray)
{
for(int ix=0;ix<_size;++ix)
os << theArray.pArray[ix] << " ";
return os;
}
int main()
{
int ia[] = {12,25,62,74,29,38,41,82};
Array<int> intArray(ia,sizeof(ia)/sizeof(ia[0]));
intArray.display();
cout << intArray << endl;
return 0;
}
但是运行程序,说链接错误,请大侠帮忙看看。