मैं विजुअल स्टूडियो 11 बीटा का उपयोग कर रहा हूं और मैं संकलन त्रुटि के बारे में उत्सुक हूं, मैं अपनी कक्षा में std :: function object संग्रहीत कर रहा हूं।क्या सी ++ 11 std :: फ़ंक्शन किसी फ़ंक्शन पॉइंटर के तर्कों की संख्या को सीमित करता है?
typedef std::function<void (int, const char*, int, int, const char*)> MyCallback;
मेरी कक्षा मैं में,
MyCallback m_callback;
यह ठीक संकलित करता है। यदि मैं सूची में एक और तर्क जोड़ता हूं तो यह विफल हो जाता है।
typedef std::function<void (int, const char*, int, int, const char*, int)> MyCallback;
विफलता है:
>c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(535): error C2027: use of undefined type 'std::_Get_function_impl<_Tx>'
1> with
1> [
1> _Tx=void (int,const char *,int,int,const char *,int)
1> ]
1> f:\development\projects\applications\my.h(72) : see reference to class template instantiation 'std::function<_Fty>' being compiled
1> with
1> [
1> _Fty=void (int,const char *,int,int,const char *,int)
1> ]
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(536): error C2504: 'type' : base class undefined
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(539): error C2027: use of undefined type 'std::_Get_function_impl<_Tx>'
1> with
1> [
1> _Tx=void (int,const char *,int,int,const char *,int)
1> ]
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(539): error C2146: syntax error : missing ';' before identifier '_Mybase'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(539): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
यह एक गतिशील रूप से जुड़े हुए पुस्तकालय जो एक और आवेदन करने के लिए पारित करने के लिए डेटा तैयारी कर रहा है। मैं निश्चित रूप से डेटा के प्रारूप को फिर से काम कर सकता हूं ताकि इसे कम तर्कों के साथ पारित किया जा सके, लेकिन मैं सोच रहा था कि मुझे यह सीमा क्यों दिखाई दे रही है?
वापस ग शैली समारोह सूचक पर स्विच किया,
typedef void (*MyCallback)(int, const char*, int, int, const char*, int);
ठीक से काम करने लगता है।
सही उत्तर। यह भी देखें [जादू और गोपनीयता] (http://channel9.msdn.com/Events/GoingNative/GoingNative-2012/STL11- मैजिक- रहस्य) एसटीएल द्वारा स्वयं गोइंगनेट 2012 में, वह इसे एक या दो बार उल्लेख करता है। – Xeo
दिलचस्प बात। मुझे याद है कि विविधता वाले टेम्पलेट्स को चीजों के जी ++ पक्ष पर केवल एक मामूली प्रयास किया जा रहा है। –
उत्कृष्ट, जो मेरे प्रश्न का उत्तर देता है, धन्यवाद! – BZor