--- In [email protected], "iamwljiang" <iamwlji...@...> wrote:
>
> 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_
Identifiers with leading underscores are reserved. Use
something like H_ARRAY_H. Don't use names like ARRAY_H
because all-cap identifiers starting with E. [cf <errno.h>]
<snip>
> /////////////////////////////////
> //
> //array.cpp
> ////////////////////////////////
Compiling a file of template definitions won't instantiate
those definitions. Hence, most C++ headers include class
and function definitions so they get instantiated when
used. The linker will then strip out duplicates.
You should look up explicit template instantiation in your
C++ book.
> #include "array.h"
> #include <stdio.h>
Why use stdio.h?!!!
<snip>
> if(alist == NULL) Error(memoryAllocationError);
Don't use NULL, use 0.
<snip>
> if(n < 0) Error(invalidArraySize);
>
> T>::~Array()
> { alist = new T[size];
Well this is screwed up! I'm surprised it compiled.
--
Peter