我用C++builder6.0编程如下
#include <iostream.h>
#include <vcl.h>
#pragma hdrstop
#include <conio.h>
#pragma argsused
template <class T>
class Array
{
protected:
T* date;
int base;
int length;
public:
Array();
Array(unsigned int,unsigned int=0);
Array(Array const&);
Array& operator=(Array const&);
T const& operator[](unsigned int)const;
T& operator[](unsigned int);
T const* Date()const;
unsigned int Base()const;
unsigned int Length()const;
void SetBase(unsigned int);
void SetLength(unsigned int);
};
template<class T>
Array<T>::Array():
data(new T[n]),base(0),length(0)
{}
template<class T>
Array<T>::Array(unsigned int n,unsigned int m):
date(new T[n]),base(m),length(n)
{}
template<class T>
T const* Array<T>::Date () const
{return date;}
template<class T>
unsigned int Array<T>::Base()const
{return base;}
template<class T>
unsigned int Array<T>::Length()const
{return length;}
template <class T>
Array<T>::Array (Array<T> const& array):
date(new T[array.length]),
base(array.base),
length(array.length)
{
for (unsigned int i=0;i<length;++i)
date[i]=array.date[i];
}
template <class T>
Array<T>& Array<T>::operator = (Array<T> const& array)
{
if (this!=&array)
{
delete [] date;
base=array.base;
length=array.length;
date=new T[length];
for (unsigned int i=0;i<length;++i)
date[i]=array.date[i];
}
return *this;
}
template <class T>
T const& Array<T>::operator[](unsigned int position) const
{
unsigned int const offset=position-base;
return date[offset];
}
//---------------------------------------------------------------------------
int main(int i,int j)
{ int const* p;
Array<int> intArr(4,8);
i=intArr.Base();
p=intArr.Date();
for(j=4;j<12;++j)
intArr[j]=j;
cout<<*p;
getch();
return 0;
发生错误如下[Linker Error] Unresolved external 'Array<int>::operator [](unsigned int)' referenced from E:\PROGRAM FILES\BORLAND\CBUILDER6\PROJECTS\DATE.OBJ