在下面的代码中,push_back()
a std::ref
into astd::vector<reference_wrapper<Type>>
效果很好,但是将 a 分配std::ref
给 areference_wrapper<Type>
不起作用。为什么?
#include <iostream>
#include <vector>
#include <functional>
using namespace std;
struct Type {};
int main()
{
Type t1;
vector<reference_wrapper<Type>> t2;
t2.push_back( ref(t1) ); // OK
//reference_wrapper<Type> t3; // error: no matching function for call to std::reference_wrapper<Type>::reference_wrapper()’
//t3 = ref(t1);
return 0;
}