में टेम्पलेट फ़ंक्शन में पॉइंटर के साथ त्रुटि संकलित करें मैं एक टेम्पलेट क्लास बनाने की कोशिश कर रहा हूं जो टेम्पलेट फ़ंक्शन पर फ़ंक्शन पॉइंटर संग्रहीत करता है, लेकिन विजुअल स्टूडियो 2008 में संकलन त्रुटि में चला गया। मैंने एक सरलीकृत परीक्षण केस बनाया इसके लिए (नीचे देखें) जो अभी भी वीएस -2008 में संकलित करने में विफल रहता है, लेकिन मैंने कोशिश की ऑनलाइन कॉमौ और ऑनलाइन जीसीसी कंपाइलर्स पर सफलतापूर्वक संकलित करने के लिए दिखाई दिया।विजुअल स्टूडियो 2008
त्रुटि मैं दिखाई दे रही है है:
error C2436: 'func' : member function or nested class in constructor initializer list
temp.cpp(21) : while compiling class template member function 'test_class<T>::test_class(T (__cdecl &))'
1> with
1> [
1> T=int (const int &)
1> ]
ही परीक्षण एक गैर टेम्पलेट समारोह काम करता है का उपयोग कर। संक्षेप में, क्या किसी को इस मुद्दे के लिए एक समाधान पता है, या यदि वीएस -2008 इस के लिए किसी प्रकार का अलग वाक्यविन्यास की उम्मीद कर रहा है?
धन्यवाद,
जेरी
template<class T>
T template_function(const T& arg)
{
return arg;
}
int non_template_function(const int& arg)
{
return arg;
}
template<class T>
class test_class
{
public:
test_class(const T& arg) : func(arg) {}
private:
T func;
};
template<class T>
void create_class(const T& arg)
{
new test_class<T>(arg);
}
int main()
{
create_class(&template_function<int>); //compile fails unless this is commented out
create_class(&non_template_function);
return 0;
}
+1, अच्छी तरह लिखित, अच्छा न्यूनतम कामकाजी उदाहरण। इसे अधिकृत रूप से उत्तर नहीं दे सकता है लेकिन त्रुटि संदेश में __cdecl लिंकेज के संबंध में अलार्म घंटी बज रहा है। – Flexo