home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!ut-emx!jamshid
- From: jamshid@ut-emx.uucp (Jamshid Afshar)
- Newsgroups: comp.lang.c++
- Subject: Re: typedefs in template class definitions
- Summary: g++ & BC++ bug; rules for template classes same as regular classes
- Message-ID: <86367@ut-emx.uucp>
- Date: 9 Jan 93 03:56:49 GMT
- References: <7648@tivoli.UUCP>
- Reply-To: jamshid@emx.utexas.edu
- Organization: The University of Texas at Austin; Austin, Texas
- Lines: 49
-
- In article <7648@tivoli.UUCP> taylor@foraker.tivoli.com (Eric Taylor) writes:
- >I am using GNU C++ ver. 2.3.3
- >I am having problems with the following type of declaration:
- >
- >template <class T>
- >class foo {
- > typedef int bar ;
- > void gag(bar x) ;
- >} ;
- >
- >template <class T>
- >void foo<T>::gag(bar x)
- >{
- >}
- >[...]
- >It does not matter if I change bar to foo<T>::bar or foo::bar
- >(actually, I get different messages).
-
- It's a compiler bug -- report it. Coincidentally, BC++ 3.1 has the
- same bug. While the following is legal,
-
- template <class T>
- void foo<T>::gag(foo<T>::bar x) {}
-
- it's unnecessary to qualify 'bar' in the parameter list since the
- parameter list, like the body of the function, is in the scope of
- foo<T>. If gag() returned a 'bar', though, you would need to qualify
- it since the return type of a function is declared in file-scope.
-
- template<class T>
- bar // error: bar not in scope, use "foo<T>::bar"
- foo<T>::gag() {}
-
- The only workaround for BC++ is to use the real type instead of the
- typedef. That's what I did throughout the JCOOL library (see
- pub/GECOOL/JCOOL.TXT at cs.utexas.edu; btw, has anyone successfully
- compiled a significant portion of it under gcc 2.3.3 or any other
- compiler?).
-
- As for your other attempt, I'm not sure if the following is legal:
- template <class T>
- void foo<T>::gag(foo::bar x) {}
-
- I think it is legal to use 'foo' without "<T>" in other situations:
- template <class T>
- void foo<T>::gag(bar x) { foo* p = this; }
- but you may have to use "<T>" with the '::' operator. Anyone?
-
- Jamshid Afshar
- jamshid@emx.utexas.edu
-