2012-02-29 10 views
14

Kod:Błąd Visual C++ 10,0 w std :: reference_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); 
} 

Wynik z MinGW g ++ 4.6.1:

 
[d:\dev\test] 
>g++ foo.cpp -std=c++0x 

[d:\dev\test] 
> _ 

Wynik z Visual 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] 
> _ 

podoba mi się sposób, że wizualna Kompilator C++ informuje użytkownika 11 razy, że klasa abstrakcyjna nie może być utworzona, tylko po to, aby ją zmusić e punkt domu, na przykład, w przypadku, gdy użytkownik nie był tego świadomy. Ale czy naprawdę powinno się utworzyć instancję klasy std::reference_wrapper? Czy nie ma sensu odwoływanie się do , a nie wymagać tworzenia instancji?

Czy jest to, jak podejrzewam, błąd w implementacji biblioteki standardowej Visual C++?

+4

Zgłosiłem [zgłoszenie błędu] (https://connect.microsoft.com/VisualStudio/feedback/details/727368/std-reference-wrapper-fails-to-wrap-reference-to-object-of-abstract -class) do Microsoft. –

+0

Czy nie powinieneś tworzyć referencyjnego_wrappera za pomocą funkcji pomocnika ref? –

+0

@jamesj: nie. to tylko funkcja pomocnicza, aby uniknąć wyraźnego określenia typu. aby zbadać błąd, lepiej mieć rzeczy jawne niż niejawne. –

Odpowiedz

4

Rozwiązany przez autora pytania. Jest to wersja bug w Visual C++ 10.0 podobno naprawiona w następnej głównej wersji VC.

+0

Być może stworzyć tę Wiki Społeczności? – Bart

+0

Dobry pomysł. Gotowe. –

Powiązane problemy