home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!wupost!darwin.sura.net!uvaarpa!murdoch!virginia.edu!gs4t
- From: gs4t@virginia.edu (Gnanasekaran Swaminathan)
- Subject: Re: Template class self-reference problem (gcc 2.2.2/libg++ 2.2)
- Message-ID: <1992Sep6.222357.7282@murdoch.acc.Virginia.EDU>
- Sender: usenet@murdoch.acc.Virginia.EDU
- Reply-To: gs4t@virginia.edu (Gnanasekaran Swaminathan)
- Organization: University of Virginia
- References: <189j7kINNd32@agate.berkeley.edu>
- Distribution: usa
- Date: Sun, 6 Sep 1992 22:23:57 GMT
- Lines: 27
-
- rwang@absolut.Berkeley.EDU (Robert Wang) writes:
-
- |> I ran into some trouble with template class self references.
- |> Referring to the code below, it seems that g++ doesn't like
- |> "const foo<bar>&" inside the definition of "template<class bar> class foo".
- |> g++ dies with the statement "parse error before >" at the line:
- |>
- |> "int operator==(const foo<bar>& rhs) const { return _data == rhs._data; }"
- |> "int operator!=(const foo<bar>& rhs) const { return _data != rhs._data; }"
- |> template<class bar> class foo
- |> {
- |> private:
- |> bar _data;
- |> public:
- |> foo(bar data) : _data(data) {}
- |>
- |> int operator==(const foo<bar>& rhs) const { return _data == rhs._data; }
- |> int operator!=(const foo<bar>& rhs) const { return _data != rhs._data; }
- |> };
-
- This is definitely a bug in gcc 2.2.2.
- However, there is a work around. Try
-
- int operator==(const foo& rhs) const { return _data == rhs._data; }
- int operator!=(const foo& rhs) const { return _data != rhs._data; }
-
- -Sekar
-