[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

automatic template instantiation

toto

10/25/2008 7:49:00 PM

Dear friends,

I'm quite new in template programming but they are giving me a very
hard time. I'm using gcc as a compiler and I'm mainly develop for
linux and windows.

My problem is that I have a template class defined and into a file,
say class.h, and implemented into another (class.cc). If I put the
implementation in the same header file, the compilation is successful
and I can also link an executable file using it.

The problem as you can imagine is when I put the implementation in a
separate file. Of course explicit instantiation is perfectly working,
but this is quite a limiting factor. I tried to see how the automatic
instantiation is working but the explanations I've found on the web
are rather confused and incomplete. I've the feeling that I have to
use the -frepo option but then the linker is failing anyway even if I
have the .rpo files.

Can you help me with this?

thanks in advance...

toto
1 Answer

Kai-Uwe Bux

10/25/2008 8:11:00 PM

0

toto wrote:

[snip]
> My problem is that I have a template class defined and into a file,
> say class.h, and implemented into another (class.cc). If I put the
> implementation in the same header file, the compilation is successful
> and I can also link an executable file using it.
>
> The problem as you can imagine is when I put the implementation in a
> separate file. Of course explicit instantiation is perfectly working,
> but this is quite a limiting factor. I tried to see how the automatic
> instantiation is working but the explanations I've found on the web
> are rather confused and incomplete.

Does that include the FAQ?

http://www.parashift.com/c++-faq-lite/templates.html...

> I've the feeling that I have to
> use the -frepo option but then the linker is failing anyway even if I
> have the .rpo files.

That feeling is a red herring.

> Can you help me with this?

Formally, you would need the "export" keyword to split header and
implementation for templates. In reality, as far as I know, only one
compiler supports "export" and it is not g++. Therefore, just put the
definition into the header file (or have the header include the
implementation file).


Best

Kai-Uwe Bux