HC4*_*ica 7 c++ templates template-function variadic-templates c++11
我将函数模板特化的地址传递给常规模板函数没有问题:
template <typename T>
void f(T) {}
template <typename A, typename B>
void foo(A, B) {}
int main()
{
foo(&f<int>, &f<float>);
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试将相同的特化传递给可变参数模板时:
template <typename T>
void f(T) {}
template <typename... A>
void bar(A...) {}
int main()
{
bar(&f<int>, &f<float>);
}
Run Code Online (Sandbox Code Playgroud)
我用GCC得到了以下编译器错误(我试过4.6.1和4.7.0):
test.cpp: In function 'int main()':
test.cpp:9:27: error: no matching function for call to 'bar(<unresolved overloaded function type>, <unresolved overloaded function type>)'
test.cpp:9:27: note: candidate is:
test.cpp:5:6: note: template<class ... A> void bar(A ...)
test.cpp:5:6: note: template argument deduction/substitution failed:
Run Code Online (Sandbox Code Playgroud)
为什么我会收到这些错误?