This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

external template instantiation example?!


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]