This is the mail archive of the gcc@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]
Other format: [Raw text]

Re: Bug or my mistake?


Lally Singh wrote:

> template<class T>
> struct foo {
>     enum { foo_value = 1 };
>
>     struct bar {
>         enum { bar_value = 1 };
>     };
>
>
>     template<class U>
>     struct baz {
>         enum { baz_value = 1 };
>     };
> };
...
>     return foo<T>::baz<U>::baz_value; // Line (3)

You need to qualify "baz" there with the "template"
keyword:

    return foo<T>::template baz<U>::baz_value;

because the compiler can't rely on "baz" naming a template:
an explicit specialization of "foo" might make it be something
else. The standard says that in such potentially-ambiguous
cases, a non-template is assumed unless you use the "template"
keyword.

Just to clarify, here's the sort of nastiness I mean.

template<>
struct foo<int> {
    int baz;
};

-- 
Gareth McCaughan



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