This code have link error,but I can't find it.I need someone help me find it 
and tell me where is error and why...

I use Dev-C++ compile it that the error show is Array(int n=50); and ~Array() 
link error. 

/////////////////////////////////////////
///Array.h 
///
///////////////////////////////////////
#ifndef _ARRAY_H_
#define _ARRAY_H_

enum ErrorType{invalidArraySize,memoryAllocationError,indexOutOfRange};


template<class T>
class Array{
      public:
             Array(int n=50);
             Array(const Array<T>& r);
             ~Array();
             
             Array<T>& operator=(const Array<T>& r);
             T& operator[](int n);
             operator T*() const;
             
             //return list size
             int ListSize(void)const;
             void Resize(int n);
             
             
             void Error(ErrorType ErrorCommitted,int badIndex=0) const;
       
       private:
             int size;
             T*  alist;         
};


#endif

/////////////////////////////////
//
//array.cpp
////////////////////////////////
#include "array.h"
#include <stdio.h>
#include <iostream>

using std::cout;
using std::endl;

void Error(ErrorType ErrorCommitted,int badIndex)
{
    char* errMsg[] = 
{"invalidArraySize","memoryAllocationError","indexOutOfRange"};
    cout <<  errMsg[ErrorCommitted] << endl;
    
    exit(1);
}


template<class T> 
Array<T>::Array(int n)
{
    size = n;
        
    if(n < 0) Error(invalidArraySize);
    
   T>::~Array()
{ alist = new T[size];
    if(alist == NULL) Error(memoryAllocationError);
    
}
template<class T>
Array<
    delete []alist;
    alist =0;
    size = 0;
}


template<class T>
Array<T>::Array(const Array<T>& r)
{
    if(r.size < 0) Error(invalidArraySize);
    size = r.size;
    delete []alist;
    
    alist = new T[size];
    if(alist == NULL) Error(memoryAllocationError);
    
    T* desptr = alist;
    T* srcptr = r.alist;
    int tmpsize = size; 
    while(tmpsize--)
        *desptr++ = *srcptr++;    
}




template<class T>
Array<T>&  Array<T>::operator =(const Array<T>& r)
{
    if(size < 0) Error(invalidArraySize);
    size = r.size;
    delete []alist;
    
    alist = new T[size];
    if(alist == NULL) Error(memoryAllocationError);
    
    T* desptr = alist;
    T* srcptr = r.alist;
    int tmpsize = size; 
    while(tmpsize--)
        *desptr++ = *srcptr++;
    
    return *this;               
}

template<class T>
T& Array<T>::operator [](int n)
{
   if(n<0 || n>size) Error(indexOutOfRange);
   return alist[n];
} 



template<class T>
Array<T>::operator T*(void)const
{
    return alist;
}

template<class T>
int Array<T>::ListSize(void)const
{
    return size;
}

template<class T>
void Array<T>::Resize(int n)
{
    if(size < 0) Error(invalidArraySize);
    if(size == n) return;
    size = n;
    
    T* desptr = new T[size];
    if(desptr == NULL) Error(memoryAllocationError); 
    T* mvptr = desptr;
    
    int tmpsize = size; 
    while(tmpsize--)
        *mvptr++ = *alist++;
    
    delete []alist;
    alist = desptr;
       
}

//////////////////////////////
//just use test
//main.cpp
///////////////////////////// 


#include "array.h"
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    //test class Array whether right.
    Array<int> iarr;
    cout << iarr.ListSize() << endl; 
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}


Reply via email to