[template] Why this doesn't compile ?

Hello,

I'm not sure why this code doesn't compile. If someone can explain, or point me to the standard where it is explained, it will be greatly appreciated.

Thank you,
Ben.

--

struct Bar
{
template<typename U>
static void bar(U) {}
};

template<typename T>
void foo()
{
T::bar(0); // WORK
T::bar<int>(0); // DON'T WORK
}

int main()
{
foo<Bar>();
return 0;
}
I've compiled your example on VS 2005
Oops, I forgot to say I was on Xcode with GCC 4.2

But if it compile on VS, now I'm curious if it's a problem with GCC or the code itself :) I'll search a little more in that direction.

Thank you for your answer.
The correct syntax is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
struct Bar
{
  template<typename U>
  static void bar(U) {}
};

template<typename T>
  void foo()
  {
    T::bar(0);
    T::template bar<int>(0); // You must tell the parser that < is not 'less than' but it's a template bracket 
  }

int main()
{
  foo<Bar>();
  return 0;
}
Topic archived. No new replies allowed.