automatic template instantiation

T

toto

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
 
K

Kai-Uwe Bux

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#faq-35.12
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,790
Messages
2,569,637
Members
45,348
Latest member
RoscoeNevi

Latest Threads

Top