address of c++ template function

Viewed 7111

Why does this fail to compile? (g++-4.5)

template < typename U >
static void h () {
}

int main () {
  auto p = &h<int>; // error: p has incomplete type
}

EDIT: Here is a work-around:

template < typename U >
static void h () {
}

int main () {
  typedef decltype (&h<int>) D;
  D p = &h<int>; // works
}
3 Answers
Related