This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
external template instantiation example?!
- To: gcc@gcc.gnu.org
- Subject: external template instantiation example?!
- From: s_fuhrm@ira.uka.de (Stephan Fuhrmann)
- Date: Wed, 18 Aug 99 11:53:14
- Reply-To: Stephan.Fuhrmann@stud.uni-karlsruhe.de
Hi there!!
I'm having a problem instantiating some template classes from other code. Here's the example
code:
**********
myclass.h: interface for 'class myclass', no functions here
template <class T> class myclass
{
public:
T a;
add(T b);
}
myclass.cpp: implementation of 'class myclass'
#include "myclass.h"
template<class T> myclass<T>::add(T b)
{
a+=b;
}
myprog.cpp: program using 'class myclass', including 'myclass.h'
#include "myclass.h"
int main(int argc,char *argv[])
{
myclass<int> i;
myclass<char> c;
c.add(2);
i.add(1);
i.add(c.a);
return 0;
}
***********
Here's my question: how can I use 'class myclass' in 'myprog.cpp' without instantiating the needed
templates before manually? Can you come up with an example? If I have to instantiate manually,
how can I do it with small effort (i.e. tell the compiler to generate all methods of the class)?
Best wishes
Stephan