help-gplusplus
[Top][All Lists]
Advanced

[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 1.5.0.10 (Windows/20070221)

michael wrote:
"Bernd Strieder" <strieder@informatik.uni-kl.de> wrote in message
news:eudpj1$id9$1@news.uni-kl.de...
Hello,

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: http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12
(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]