By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,672 Members | 1,644 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,672 IT Pros & Developers. It's quick & easy.

automatic template instantiation

P: n/a
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
Oct 25 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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-lit...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
Oct 25 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.