C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

template implementation not seen by the compiler

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Christof Warlich
Guest





PostPosted: Sun Aug 13, 2006 9:10 am    Post subject: template implementation not seen by the compiler Reply with quote



Hi,

consider this:

template<typename T> class X {
public:
void doSomething(T t);
};
int main(void) {
X<int> x;
x.doSomething(4);
return 0;
}

It compiles fine but the linker is missing the implementation of
doSomething().

Why may it ever make sense that the compilation of this works fine? The
compiler already _knows_ that it could not instantiate doSomething() for
type int since it has not seen the (template) implementation of
doSomething(). Thus, linking will _always_ fail. Or do I miss a way to
pass the doSomething() implementation for a specific type to the linker
from another object file?

Thanks for any help,

Christof
Back to top
Rolf Magnus
Guest





PostPosted: Sun Aug 13, 2006 9:10 am    Post subject: Re: template implementation not seen by the compiler Reply with quote



Christof Warlich wrote:

Quote:
Hi,

consider this:

template<typename T> class X {
public:
void doSomething(T t);
};
int main(void) {
X<int> x;
x.doSomething(4);
return 0;
}

It compiles fine but the linker is missing the implementation of
doSomething().

Why may it ever make sense that the compilation of this works fine? The
compiler already _knows_ that it could not instantiate doSomething() for
type int since it has not seen the (template) implementation of
doSomething().

It might not need to.

Quote:
Thus, linking will _always_ fail.

No. There could be another translation unit that defines doSomething() and
also instantiates the template for int. Then there would be an
implementation, but only the linker could find it.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.