我刚才遇到了一个奇怪的问题。
源码简单明了,如下:
#include <vector>
#include <iostream>
#include <functional>
using namespace std;
using namespace std::tr1;
template<class T_>
void show_size(T_ coll)
{
cout << coll.size();
}
int main()
{
vector<int> coll;
coll.push_back(1);
show_size(ref(coll));
return 0;
}
VC++ 2010 报告:
错误 C2039:“大小”:不是“std::tr1::reference_wrapper<_Ty>”的成员
众所周知,reference_wrapper 可以自动将自身转换为其底层类型,这里是vector<int>. 为什么这么简单的代码无效?