मैं इस कोड (एक अधिक जटिल संस्करण से सरलीकृत) है: यदि मैं जीसीसी 4.6.3 पर यह संकलन यह संकलित g++ -std=c++0x filename.cpp
का उपयोग करvariadic टेम्पलेट कोड जीसीसी 4.6 पर संकलित लेकिन बजना पर नहीं या जीसीसी 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);
}
ठीक तथापि बजना 3.0 clang++ -std=c++0x filename.cpp
का उपयोग कर इसे निम्न त्रुटि फेंकता पर:
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'
012:
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.
जीसीसी 4.7.2 पर भी कोई त्रुटि है
अब सवाल यह है कि: यह क्यों विफल रहा है या मैं क्या गलत कर रहा हूं?
क्या आपने '' को हटाने का प्रयास किया था? जहां संभव हो सी ++ टेम्पलेट प्रकार कटौती का उपयोग करता है। –
leemes
जी ++ 4.7 त्रुटि संदेश: http://ideone.com/qwSKJl तर्क आदेश के साथ एक समस्या प्रतीत होती है। – leemes
@leemes: मैंने कोशिश की और इससे – eyelash