[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: linker error with template class

From: red floyd
Subject: Re: linker error with template class
Date: Thu, 29 Mar 2007 15:43:53 GMT
User-agent: Thunderbird (Windows/20070221)

michael wrote:
"Bernd Strieder" <> wrote in message

michael wrote:

I have the following in a class:

template<class T>
bool Utility::getInput(T& i, T low, T up){

in another file and class I have :

Utility utility;
utility.getInput(sal, 0.0, 999999.99);
utility.getInput(sid, 0, 999999);

Now, if I put all this in one file it compiles no worries. But, if I
compile it as is i get an error from the linker:
Check the object files for the instances the compiler has created, and
you will see, that in the error case, the missing instance has not been
created anywhere. A template instance can only be created if the
template source code is included with the translation unit.

probably a silly question, but how can I check what's in the object files?

There is a section on template instantiation in the gcc info pages,
which should answer your question and provide the possibilities to
resolve your problem.

In the end you will probably have the template code included at the end
of the template header file, so the templates can be instantiated,
wherever they are used, and the linker can remove duplicates.

using gnu g++ v3.3.3 (same result on 3.4.2)
Probably same result on every existing C++ compiler.

Look here:
(as well as 35.13, 35.14, 35.15 and 35.16).

It's a FAQ on comp.lang.c++. Essentially, you need the template implementation visible from the point of instantiation.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]