在 Visual C++ 2013 中,以下代码给我一个“模棱两可的调用”编译错误:
typedef vector<int> V;
V v;
auto b1 = bind(&V::at, &v);
现在我四处搜索,发现我应该转换到我想要的签名。所以我这样做:
auto b2 = bind(static_cast<int(V::*)(V::size_type)>(&V::at), &v);
现在,错误是:
'static_cast' : cannot convert from 'overloaded-function' to 'int (__thiscall std::vector<_Ty>::* )(unsigned int)'
我怎样才能正确地做到这一点?
最佳答案
V::at
的返回类型是V::reference
:
auto b = std::bind(static_cast<V::reference (V::*)(V::size_type)>(&V::at), v);
不用说,这是一种可憎的行为。
关于c++ - 如何绑定(bind)到 vector<>::at?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21337618/