home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18868 < prev    next >
Encoding:
Text File  |  1993-01-08  |  2.0 KB  |  63 lines

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!ut-emx!jamshid
  2. From: jamshid@ut-emx.uucp (Jamshid Afshar)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: typedefs in template class definitions
  5. Summary: g++ & BC++ bug; rules for template classes same as regular classes
  6. Message-ID: <86367@ut-emx.uucp>
  7. Date: 9 Jan 93 03:56:49 GMT
  8. References: <7648@tivoli.UUCP>
  9. Reply-To: jamshid@emx.utexas.edu
  10. Organization: The University of Texas at Austin; Austin, Texas
  11. Lines: 49
  12.  
  13. In article <7648@tivoli.UUCP> taylor@foraker.tivoli.com (Eric Taylor) writes:
  14. >I am using GNU C++ ver. 2.3.3
  15. >I am having problems with the following type of declaration:
  16. >
  17. >template <class T>
  18. >class foo {
  19. >    typedef int bar ;
  20. >    void gag(bar x) ;
  21. >} ;
  22. >
  23. >template <class T>
  24. >void foo<T>::gag(bar x)
  25. >{
  26. >}
  27. >[...]
  28. >It does not matter if I change bar to foo<T>::bar or foo::bar
  29. >(actually, I get different messages).
  30.  
  31. It's a compiler bug -- report it.  Coincidentally, BC++ 3.1 has the
  32. same bug.  While the following is legal,
  33.  
  34.     template <class T>
  35.     void foo<T>::gag(foo<T>::bar x) {}
  36.  
  37. it's unnecessary to qualify 'bar' in the parameter list since the
  38. parameter list, like the body of the function, is in the scope of
  39. foo<T>.  If gag() returned a 'bar', though, you would need to qualify
  40. it since the return type of a function is declared in file-scope.
  41.  
  42.     template<class T>
  43.     bar  // error: bar not in scope, use "foo<T>::bar"
  44.     foo<T>::gag() {}
  45.  
  46. The only workaround for BC++ is to use the real type instead of the
  47. typedef.  That's what I did throughout the JCOOL library (see
  48. pub/GECOOL/JCOOL.TXT at cs.utexas.edu; btw, has anyone successfully
  49. compiled a significant portion of it under gcc 2.3.3 or any other
  50. compiler?).
  51.  
  52. As for your other attempt, I'm not sure if the following is legal:
  53.     template <class T>
  54.     void foo<T>::gag(foo::bar x) {}
  55.  
  56. I think it is legal to use 'foo' without "<T>" in other situations:
  57.     template <class T>
  58.     void foo<T>::gag(bar x) { foo* p = this; }
  59. but you may have to use "<T>" with the '::' operator.  Anyone?
  60.  
  61. Jamshid Afshar
  62. jamshid@emx.utexas.edu
  63.