home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / gnu / g / bug / 2084 < prev    next >
Encoding:
Text File  |  1992-12-29  |  2.3 KB  |  72 lines

  1. Newsgroups: gnu.g++.bug
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!cs.rice.edu!dougm
  3. From: dougm@cs.rice.edu (Doug Moore)
  4. Subject: 2.3.3: template/operator- bug
  5. Message-ID: <9212280801.AA05912@cs.rice.edu>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Mon, 28 Dec 1992 08:01:12 GMT
  10. Approved: bug-g++@prep.ai.mit.edu
  11. Lines: 59
  12.  
  13. In the following program, I find that a friend binary operator - and a
  14. member operator - w/ no args cannot co-exist in the same template class;
  15. the result of an attempt is a link error.
  16.  
  17. Note that if the member minus without args is replaced by a friend
  18. minus with one arg, the problem disappears.
  19.  
  20. First the compiler:  gcc 2.3.3, original sources, on a sparc (sunos
  21. 4.1.2).
  22.  
  23. The compiler output:
  24. ==============================================================================
  25. g++ -v -Wall bug.cc
  26. Reading specs from /blossom/lib/gcc-lib/sun4/2.3.3/specs
  27. gcc version 2.3.3
  28.  /blossom/lib/gcc-lib/sun4/2.3.3/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix -Wall bug.cc /usr/tmp/cca05901.i
  29. GNU CPP version 2.3.3 (sparc)
  30.  /blossom/lib/gcc-lib/sun4/2.3.3/cc1plus /usr/tmp/cca05901.i -quiet -dumpbase bug.cc -Wall -version -o /usr/tmp/cca05901.s
  31. GNU C++ version 2.3.3 (sparc) compiled by GNU C version 2.3.3.
  32.  as -o /usr/tmp/cca059011.o /usr/tmp/cca05901.s
  33.  /blossom/lib/gcc-lib/sun4/2.3.3/ld -e start -dc -dp /lib/crt0.o -L/blossom/lib/gcc-lib/sun4/2.3.3 -L/blossom/lib /usr/tmp/cca059011.o -lg++ -lgcc -lc -lgcc
  34. ld: Undefined symbol 
  35.    ___mi__FRCt6Number1ZiT0 
  36. collect: /usr/bin/ld returned 2 exit status
  37. ==============================================================================
  38.  
  39. The source:
  40. ==============================================================================
  41. template<class T>
  42. class Number
  43. {
  44. public:
  45. friend Number operator- (const Number& src1, const Number& src2);
  46.   Number operator- () const;
  47.   T data;
  48. };
  49.  
  50. template <class T>
  51. inline Number<T>
  52. operator- (const Number<T>& src1, const Number<T>& src2)
  53. {
  54.   Number<T> dst;
  55.   dst.data = src1.data - src2.data;
  56.   return dst;
  57. }
  58.  
  59. main()
  60. {
  61.   Number<int> a, b, c;
  62.   b.data = 1;
  63.   c.data = 2;
  64.   a = b - c;
  65. }
  66. ==============================================================================
  67.  
  68. Doug Moore
  69. (dougm@cs.rice.edu)
  70.  
  71.  
  72.