This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: typedef, class template and inheritance
- To: Gabriel Dos Reis <Gabriel dot Dos-Reis at dptmaths dot ens-cachan dot fr>
- Subject: Re: typedef, class template and inheritance
- From: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Date: 03 Oct 1997 15:07:41 -0300
- Cc: egcs-bugs at cygnus dot com
- References: <199710030106.DAA07262@basson.dptmaths.ens-cachan.fr>
Gabriel Dos Reis writes:
> % g++ -c toto.C
> toto.C:13: new declaration `T bar<T>::foobar()'
> toto.C:10: ambiguates old declaration `typename foo<T,T>::fred_t bar<T>::foobar()'
> gcc shouldn't flag the former code not legal. Should it ?
Yup. In fact, the declaration of foobar inside the body of bar<T>
should not be accepted. foo<T,T>::fred_t is not visible at that
point, since foo<T,T> might be specialized so that it does not declare
a fred_t type for some type T.
Instead of declaring the typedef as you did, you might have written:
template <class T> struct bar : public foo<T, T> {
typename foo<T,T>::fred_t foobar();
};
template <class T> typename foo<T,T>::fred_t bar<T>::foobar() {
return fred_t();
}
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
Universidade Estadual de Campinas, SP, Brasil