3

I'm trying to compile the following code:

struct A {
    template<int N> static void a() {}
};

template<> void A::a<5>() {}

template<class T>
struct B {
    static void b() {
        T::a<5>();
    }
};

void test() {
    A::a<5>();
    B<A>::b();
}

and compiler interprets < in T::a<5> as an operator <, resulting in error:

invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator<’

Is there any way to explicitly instantiate T::a<5> without compiler errors? Thank you.

gcc version 4.5.1 20100924 (Red Hat 4.5.1-4) (GCC)

John Dibling
  • 99,718
  • 31
  • 186
  • 324
user1072688
  • 61
  • 1
  • 4
  • possible duplicate of [template disambiguator](http://stackoverflow.com/questions/4077110/template-disambiguator) – iammilind Nov 30 '11 at 05:22

1 Answers1

6

Yes, change that line to:

T::template a<5>();

Compiler doesn't know if T::a is a function (because of its template nature). By mentioning template, you inform compiler explicitly. This question is asked many times, here is one of them.

Community
  • 1
  • 1
iammilind
  • 68,093
  • 33
  • 169
  • 336