home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13352 < prev    next >
Encoding:
Text File  |  1992-09-08  |  1.5 KB  |  41 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!wupost!darwin.sura.net!uvaarpa!murdoch!virginia.edu!gs4t
  3. From: gs4t@virginia.edu (Gnanasekaran Swaminathan)
  4. Subject: Re: Template class self-reference problem (gcc 2.2.2/libg++ 2.2)
  5. Message-ID: <1992Sep6.222357.7282@murdoch.acc.Virginia.EDU>
  6. Sender: usenet@murdoch.acc.Virginia.EDU
  7. Reply-To: gs4t@virginia.edu (Gnanasekaran Swaminathan)
  8. Organization: University of Virginia
  9. References:  <189j7kINNd32@agate.berkeley.edu>
  10. Distribution: usa
  11. Date: Sun, 6 Sep 1992 22:23:57 GMT
  12. Lines: 27
  13.  
  14. rwang@absolut.Berkeley.EDU (Robert Wang) writes:
  15.  
  16. |> I ran into some trouble with template class self references.
  17. |> Referring to the code below, it seems that g++ doesn't like 
  18. |> "const foo<bar>&" inside the definition of "template<class bar> class foo".
  19. |> g++ dies with the statement "parse error before >" at the line:
  20. |> 
  21. |>    "int operator==(const foo<bar>& rhs) const { return _data == rhs._data; }"
  22. |>    "int operator!=(const foo<bar>& rhs) const { return _data != rhs._data; }"
  23. |> template<class bar> class foo
  24. |>    {
  25. |> private:
  26. |>    bar _data;
  27. |> public:
  28. |>    foo(bar data) : _data(data) {}
  29. |> 
  30. |>    int operator==(const foo<bar>& rhs) const { return _data == rhs._data; }
  31. |>    int operator!=(const foo<bar>& rhs) const { return _data != rhs._data; }
  32. |>    };
  33.  
  34. This is definitely a bug in gcc 2.2.2.
  35. However, there is a work around. Try
  36.  
  37.  int operator==(const foo& rhs) const { return _data == rhs._data; }
  38.  int operator!=(const foo& rhs) const { return _data != rhs._data; }
  39.  
  40. -Sekar
  41.