我有一个奇怪的错误,试图对指针向量使用for_each迭代
我想在每个指针上调用一个方法
objects_ 是类型的 vector<someClass*>
for_each(objects_.begin(), objects_.end(), std::bind1st(std::mem_fun(&someClass::someMethod), this));
Run Code Online (Sandbox Code Playgroud)
但这甚至没有编译,因为:
error C2039: 'bind1st' : is not a member of 'std'
error C2039: 'mem_fun' : is not a member of 'std'
error C3861: 'bind1st': identifier not found
error C3861: 'mem_fun': identifier not found
Run Code Online (Sandbox Code Playgroud)
然而,其他stl algortihms和方法正常工作.
我错过了什么吗?
std::bind1st并且std::mem_fn位于<functional>标题中,只要您包含该文件,您的翻译单元就会显示:
#include <functional>
Run Code Online (Sandbox Code Playgroud)
另外,请注意,std::bind1st被弃用,你应该使用lambda表达式或更通用std::bind.