我有這樣的代碼(從一個更復雜的簡化版本):可變參數模板的代碼編譯的GCC 4.6,但不是在鐺或GCC 4.7
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);
}
如果我使用g++ -std=c++0x filename.cpp
它編譯編譯它GCC 4.6.3然而細使用clang++ -std=c++0x filename.cpp
它引發以下錯誤鐺3.0:
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'
現在的問題是:它爲什麼失敗或我做錯了什麼?
您是否嘗試刪除''? C++在可能的情況下使用模板類型演繹。 –
leemes
g ++ 4.7錯誤信息:http://ideone.com/qwSKJl參數排序似乎有問題。 – leemes
@眼鏡:我試過了,它沒有幫助 – eyelash