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: michael
Subject: Re: linker error with template class
Date: Thu, 29 Mar 2007 17:03:35 +0800

"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.
>
> Bernd Strieder
>

Thanks for your help




reply via email to

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