Visual C ++ 10.0错误在std :: reference中

码:

#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 );
}

使用MinGW g ++ 4.6.1的结果:

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

[d:devtest]
> _

Visual C ++ 10.0的结果:

[d:devtest]
> cl foo.cpp
foo.cpp
C:Program Files (x86)Microsoft Visual Studio 10.0VCINCLUDExxcallwrap(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.0VCINCLUDExrefwrap(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.0VCINCLUDExrefwrap(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.0VCINCLUDExxcallwrap(8) : error C2027: use of undefined type 'std::
tr1::_Result_of'
        with
        [
            _Ty=const Foo (void)
        ]
C:Program Files (x86)Microsoft Visual Studio 10.0VCINCLUDExxcallwrap(9) : error C2143: syntax error : missing ';' before '('
C:Program Files (x86)Microsoft Visual Studio 10.0VCINCLUDExxcallwrap(9) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:Program Files (x86)Microsoft Visual Studio 10.0VCINCLUDExxcallwrap(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:Program Files (x86)Microsoft Visual Studio 10.0VCINCLUDExxcallwrap(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.0VCINCLUDExxcallwrap(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.0VCINCLUDExxcallwrap(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.0VCINCLUDExxcallwrap(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.0VCINCLUDExxcallwrap(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.0VCINCLUDExxcallwrap(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.0VCINCLUDExxcallwrap(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.0VCINCLUDExxcallwrap(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.0VCINCLUDExxcallwrap(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.0VCINCLUDExxcallwrap(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:devtest]
> _

我喜欢Visual C ++编译器11次告诉用户抽象类不能被实例化的方式,只是为了将这一点敲回家,就像用户不知道那样。 但是,应该std::reference_wrapper真正实例化类? (通过)参考的大部分内容不需要实例化?

也就是说,我强烈怀疑这是Visual C ++标准库实现中的一个错误吗?


通过问题作者解决。 这是Visual C ++ 10.0中的一个错误,据称可以在VC的下一个主要版本中修复它。

链接地址: http://www.djcxy.com/p/29745.html

上一篇: Visual C++ 10.0 bug in std::reference

下一篇: adding an external property to include index for vertix in graph (boost)