473,414 Members | 1,675 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

automatic template instantiation

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
1 1545
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dave | last post by:
Hello all, Consider this function template definition: template<typename T> void foo(T) {} If foo is never called, this template will never be instantiated. Now consider this explicit...
7
by: Drew McCormack | last post by:
I have a C++ template class which contains a static variable whose construction registers the class with a map. Something like this: template <typename T> class M { static Registrar<M>...
4
by: Dave | last post by:
Hello all, Consider this template: template <typename T> void foo(T bar) {...} Here are three ways to instantiate this: 1.
12
by: mlimber | last post by:
This is a repost (with slight modifications) from comp.lang.c++.moderated in an effort to get some response. I am using Loki's Factory as presented in _Modern C++ Design_ for message passing in...
2
by: Rudy Ray Moore | last post by:
Whenever I get any error with Vc++7.1/.net/2003, it is followed by huge ammounts of "template assistance" error messaging referencing template code (MTL) that has nothing to do with the error. ...
3
by: sks | last post by:
Hello all Is the usage of extern keyword valid for telling the compiler to NOT instantiate a template and to link it from an another binary? For example: Suppose module A's binary contains a...
5
by: edd | last post by:
Hello all, Please consider: template<typename Tclass my_class; template<class my_class<int> { //... };
2
by: Uwe Mayer | last post by:
Hi, I am writing a library, which contains classes with template memberfunctions. If I do not instanciate the templates I want to use, I get an "undefined reference" link-error. The FAQ...
4
by: Pallav singh | last post by:
Hi All, i am getting error during explicit function Instantiation for a class Template if i do explicit Instantiation of class it work and all function symbol i get in object file But if i...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.