【发布时间】:2012-02-07 17:22:55
【问题描述】:
一些简单的代码将演示这个问题:
class Foo {};
struct Bar {
bool foo(const Foo &f) const { return false; }
};
int main() {
Bar bar;
vector<Foo> v;
std::find_if(v.begin(), v.end(), std::bind1st(
std::mem_fun_ref(&Bar::foo), bar));
return 0;
}
现在,对于这段代码,VS2010 c++ 编译器会报错: 错误 C2535: bool std::binder1st<_fn2>::operator()(const Foo&) const: 已声明的成员函数
在早期版本的 Visual Studio 中,还会出现两个与引用问题相关的编译错误。虽然这些问题在 VS2010 中已经消失,但 C2535 仍然存在。
这个问题类似于this one。正如那篇文章所建议的,我可以使用 std::bind 或 boost 库作为替代方案。它们工作得很好,但是现在,我想知道在这种情况下是否可以使用旧的 bind1st 样式,或者这个问题更多的是 STL 功能框架中固有的缺陷? 谢谢!
【问题讨论】: