address of c++ template function

后端 未结 3 1646
一生所求
一生所求 2021-01-07 18:41

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

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

int main () {
  auto p = &h; // error: p has inco         


        
3条回答
  •  春和景丽
    2021-01-07 18:57

    It does not compile because type of 'p' is not known to the compiler which is a must in C++ unlike some other languages.

    Try

    template < typename U > 
    static void h () { 
    } 
    
    int main () { 
      auto void (*p)() = &h; 
    } 
    

提交回复
热议问题