address of c++ template function

后端 未结 3 1658
一生所求
一生所求 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 19:00

    In C++0x this is guaranteed to work. However in C++03 this wasn't working (the initializer part, that is) and some compilers apparently don't support it yet.

    Furthermore, I remember that the C++0x wording is not clear what happens with &h when it is an argument to a function template and the corresponding parameter is deduced (this is what auto is translated to, conceptionally). The intention is, however, that it is valid. See this defect report where they designed the wording, the example by "Nico Josuttis" and their final example.

    There is another rule that the wording enforces but compilers are not correctly implementing. For example, see this clang PR.

提交回复
热议问题