कोड: MinGW जी के साथ ++ 4.6.1दृश्य सी ++ 10.0 बग std :: context_wrapper में?
#include <functional>
struct Foo
{
virtual void mf() = 0;
};
struct Bar: Foo
{
virtual void mf() {}
};
int main()
{
Bar o;
std::reference_wrapper<Foo const> wrapper(o);
}
परिणाम:
[d:\dev\test] >g++ foo.cpp -std=c++0x [d:\dev\test] > _
विजुअल C++ 10.0 के साथ परिणाम:
[d:\dev\test] >cl foo.cpp foo.cpp C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class due to following members: 'void Foo::mf(void)' : is abstract foo.cpp(5) : see declaration of 'Foo::mf' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xrefwrap(371) : see reference to class template instantiation 'std::tr1::_Call_wrapper' being compiled with [ _Callable=std::tr1::_Callable_obj ] C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xrefwrap(416) : see reference to class template instantiation 'std::tr1::_Refwrap_impl' being compiled with [ _Ty=const Foo ] foo.cpp(16) : see reference to class template instantiation 'std::tr1::reference_wrapper' being compiled with [ _Ty=const Foo ] C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2027: use of undefined type 'std:: tr1::_Result_of' with [ _Ty=const Foo (void) ] C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(9) : error C2143: syntax error : missing ';' before '(' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(9) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class due to following members: 'void Foo::mf(void)' : is abstract foo.cpp(5) : see declaration of 'Foo::mf' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class due to following members: 'void Foo::mf(void)' : is abstract foo.cpp(5) : see declaration of 'Foo::mf' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class due to following members: 'void Foo::mf(void)' : is abstract foo.cpp(5) : see declaration of 'Foo::mf' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class due to following members: 'void Foo::mf(void)' : is abstract foo.cpp(5) : see declaration of 'Foo::mf' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class due to following members: 'void Foo::mf(void)' : is abstract foo.cpp(5) : see declaration of 'Foo::mf' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class due to following members: 'void Foo::mf(void)' : is abstract foo.cpp(5) : see declaration of 'Foo::mf' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class due to following members: 'void Foo::mf(void)' : is abstract foo.cpp(5) : see declaration of 'Foo::mf' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class due to following members: 'void Foo::mf(void)' : is abstract foo.cpp(5) : see declaration of 'Foo::mf' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class due to following members: 'void Foo::mf(void)' : is abstract foo.cpp(5) : see declaration of 'Foo::mf' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class due to following members: 'void Foo::mf(void)' : is abstract foo.cpp(5) : see declaration of 'Foo::mf' [d:\dev\test] > _
मैं तरीका है कि दृश्य की तरह सी ++ कंपाइलर उपयोगकर्ता को 11 बार बताता है कि अमूर्त वर्ग को तत्काल नहीं किया जा सकता है, केवल वें हथियाने के लिए ई बिंदु घर, जैसे, अगर उपयोगकर्ता को इसके बारे में पता नहीं था। लेकिन std::reference_wrapper
वास्तव में वर्ग को तुरंत चालू करना चाहिए? पर तत्कालता की आवश्यकता नहीं है (पास से) संदर्भ का अधिकांश बिंदु नहीं है?
आईई, क्या यह दृढ़ता से संदेह है, दृश्य सी ++ मानक पुस्तकालय कार्यान्वयन में एक बग?
मैंने एक [बग रिपोर्ट] सबमिट की है (https://connect.microsoft.com/VisualStudio/feedback/details/727368/std-reference-wrapper-fails-to-wrap-reference-to-object-of-abstract क्लास) - माइक्रोसॉफ्ट के लिए। –
क्या आप रेफरी हेल्पर फ़ंक्शन के साथ संदर्भ_वापर नहीं बना रहे हैं? –
@jamesj: नहीं। यह स्पष्ट रूप से प्रकार निर्दिष्ट करने से बचने के लिए, केवल एक सहायक कार्य है। एक बग की जांच करने के लिए चीजों को स्पष्ट से स्पष्ट करना बेहतर होता है। –