This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: class template


On 11 June 2011 00:48, eric wrote:
> Dear g++ programers:
>
> ?I tried to copy a simple code about template and class which use arry
> of (int or double or char)
> but I can not get pass compile(g++4.5.2, I install gcc 4.5.2 but not
> gcc-g++ 4.5.2; however when I g++ -v, it still show it is 4.5.2 from
> my old 4.4.3) from a book (C++Primer3rdEd, chapter2). ?Please help. Eric
> ----------------------------------
>
> eric@eric-laptop:~/CppPrimer3$ g++ Array.cpp pg52.cpp
> /tmp/ccE9MPMg.o: In function `main':
> pg52.cpp:(.text+0x23): undefined reference to `Array<int>::Array(int)'
> pg52.cpp:(.text+0x37): undefined reference to
> `Array<double>::Array(int)'
> pg52.cpp:(.text+0x4b): undefined reference to `Array<char>::Array(int)'
> collect2: ld returned 1 exit status

This error means the linker can't find the definition of the
Array<int> constructor, which is needed because some of your code
refers to it.

> ?// parameterize element type
> ?explicit Array( int size = DefaultArraySize );

This is the Array constructor which is not defined.

You have either not copied the code correctly, or you have not
followed the book's instructions correctly, or the book is wrong.

Noone on this list can help you unless they have a copy of the book to
see the code or instructions that you haven't shown.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]