This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: typedef, class template and inheritance


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]