我有这个代码(从更复杂的版本简化):
template <class... A1> class Test {
public:
template <class... A2> void print (void(*function)(A2...,A1...)) {
}
};
void test_print (int a, float b, double c) {
}
int main () {
Test<float,double> test;
test.print<int> (&test_print);
}
如果我在 GCC 4.6.3 上使用g++ -std=c++0x filename.cpp
它编译它可以正常编译,但是在 clang 3.0 上使用clang++ -std=c++0x filename.cpp
它会引发以下错误:
filename.cpp:14:10: error: no matching member function for call to 'print'
test.print<int> (&test_print);
~~~~~^~~~~~~~~~
filename.cpp:3:33: note: candidate template ignored: failed template argument deduction
template <class... A2> void print (void(*function)(A2...,A1...)) {
^
1 error generated.
在 GCC 4.7.2 上也有一个错误:
filename.cpp: In function 'int main()':
filename.cpp:14:33: error: no matching function for call to 'Test<float, double>::print(void (*)(int, float, double))'
filename.cpp:14:33: note: candidate is:
filename.cpp:3:33: note: template<class ... A2> void Test::print(void (*)(A2 ..., A1 ...)) [with A2 = {A2 ...}; A1 = {float, double}]
filename.cpp:3:33: note: template argument deduction/substitution failed:
filename.cpp:14:33: note: mismatched types 'float' and 'int'
现在的问题是:为什么它会失败或者我做错了什么?