C++ 使用std::reference\u包装的编译器错误

C++ 使用std::reference\u包装的编译器错误,c++,c++11,C++,C++11,我想你可以更新你的编译器 请参阅链接:$6无匹配函数用于调用\u2018std::list,std::allocator>::push_back(foo&)。这就解释了MSVC接受它的原因。它有一个邪恶的扩展名。变量名很奇怪。好吧,那么如何使用g++@XYZ更新到g++4.7来实现上述功能呢?(4.6似乎也能工作。)GCC4.4.6已经过时了。 #include <functional> #include <algorithm> #include <list>

我想你可以更新你的编译器


请参阅链接:$6

无匹配函数用于调用\u2018std::list,std::allocator>::push_back(foo&)
。这就解释了MSVC接受它的原因。它有一个邪恶的扩展名。变量名很奇怪。好吧,那么如何使用g++@XYZ更新到g++4.7来实现上述功能呢?(4.6似乎也能工作。)GCC4.4.6已经过时了。
#include <functional>
#include <algorithm>
#include <list>
using namespace std;

struct foo{
  int _val;
};

int main(){
  list<foo> A;
  foo B;
  for(int i=0;i<10;++i){
    B._val=i;
    A.push_back(B);
  }
  list< reference_wrapper < foo > > C(A.begin(),A.end());
return 0;
}
>In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/list:63,
from ref_wrapper.cpp:4:/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_list.h: In member function \u2018void std::list<_Tp, _Alloc>::_M_initialize_dispatch(_InputIterator, _InputIterator, std::__false_type) [with _InputIterator = std::_List_iterator<foo>, _Tp = std::reference_wrapper<foo>, _Alloc = std::allocator<std::reference_wrapper<foo> >]\u2019:
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_list.h:577:   instantiated from \u2018std::list<_Tp, _Alloc>::list(_InputIterator, _InputIterator, const _Alloc&) [with _InputIterator = std::_List_iterator<foo>, _Tp = std::reference_wrapper<foo>, _Alloc = std::allocator<std::reference_wrapper<foo> >]\u2019
ref_wrapper.cpp:19:   instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_list.h:1361: error: no matching function for call to \u2018std::list<std::reference_wrapper<foo>, std::allocator<std::reference_wrapper<foo> > >::push_back(foo&)\u2019
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_list.h:919: note: candidates are: void std::list<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = std::reference_wrapper<foo>, _Alloc = std::allocator<std::reference_wrapper<foo> >]
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_list.h:924: note:                 void std::list<_Tp, _Alloc>::push_back(_Tp&&) [with _Tp = std::reference_wrapper<foo>, _Alloc = std::allocator<std::reference_wrapper<foo> >]
 g++ -std=gnu++0x reference_wrapper_test.cpp -o reference_wrapper_test