home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13277 < prev    next >
Encoding:
Text File  |  1992-09-03  |  1.2 KB  |  64 lines

  1. Path: sparky!uunet!dtix!darwin.sura.net!wupost!usc!sol.ctr.columbia.edu!usenet.ucs.indiana.edu!nsundare@silver.ucs.indiana.edu
  2. From: nsundare@silver.ucs.indiana.edu (Neelakantan Sundaresan)
  3. Newsgroups: comp.lang.c++
  4. Subject: Problem with templates...
  5. Message-ID: <Bu0xvC.6np@usenet.ucs.indiana.edu>
  6. Date: 3 Sep 92 22:45:07 GMT
  7. Sender: <nsundare@silver.ucs.indiana.edu>
  8. Organization: Indiana University
  9. Lines: 52
  10. X-Mailer: ELM [version 2.3 PL11]
  11.  
  12.  
  13. I am trying to separate compile template definitions and use.
  14. For instance,
  15.  file1.c has
  16.  -----
  17.  
  18. #include <stdio.h>
  19. #include <stdarg.h>
  20. #include "file1.h"
  21.  
  22. template <class T> XT<T>::Xtest(T t)
  23. { printf("HEE\n");
  24.   return 0;
  25. }
  26. template <class T> XT<T>::XT(){}
  27.  
  28.  file2.c has
  29.  ------
  30.  
  31. #include <stdio.h>
  32. #include <stdarg.h>
  33. #include "file1.h"
  34.  
  35. main()
  36. {
  37.   typedef XT<int> Y;
  38.   Y x;
  39.   x.Xtest(4);
  40. }
  41.  
  42.   file1.h has
  43.   -------
  44.  
  45. template <class T> class XT {
  46.  public:
  47.    XT();
  48.    Xtest(T);
  49. };
  50.  
  51.  
  52. ------------ On compiling with g++ and linking I get the error
  53.  undefined symbol:
  54.      ___t2XT1Zi 
  55.          _Xtest__t2XT1Zii 
  56.  
  57. But if I have file1.c and file2.c in the same file, everything seems
  58. to be okay.
  59.  
  60.  
  61. Any ideas as to what is going on?
  62. thanks
  63. Neel.
  64.