std :: reference_wrapper中的Visual C ++ 10.0错误? [英] Visual C++ 10.0 bug in std::reference_wrapper?

查看:262
本文介绍了std :: reference_wrapper中的Visual C ++ 10.0错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码:

#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的结果:

Result with MinGW g++ 4.6.1:


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

[d:\dev\test]
> _

Visual C ++ 10.0的结果:

Result with 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]
> _

像Visual C ++编译器告诉用户11次抽象类不能被实例化的方式,只是为了将点击回家,就像在用户不知道的情况下。但是 std :: reference_wrapper 真的实例化类吗?对于不是的引用不是很需要实例化?

I like the way that the Visual C++ compiler tells the user 11 times that the abstract class cannot be instantiated, just to hammer the point home, like, in case the user was not aware of that. But should std::reference_wrapper really instantiate the class? Is not much of the point of (passing by) reference to not require instantiation?

这是我强烈怀疑的Visual C ++标准库实现中的错误?

I.e., is this, as I strongly suspect, a bug in the Visual C++ standard library implementation?

推荐答案

这是一个错误在Visual C ++ 10.0据说固定在下一个主要版本的VC。

Solved by question author. It is a bug in Visual C++ 10.0 supposedly fixed in the next major version of VC.

这篇关于std :: reference_wrapper中的Visual C ++ 10.0错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆