c++ - 如何使用 std::for_each 和 boost::bind 在参数上调用成员函数?

标签 c++ visual-studio-2008 boost stl boost-bind

我想使用 std::for_each 将一系列字符串添加到组合框中。这些对象属于 Category 类型,我需要对它们调用 GetName。我如何使用 boost::bind 实现此目的?

const std::vector<Category> &categories = /**/;
std::for_each(categories.begin(), categories.end(), boost::bind(&CComboBox::AddString, &comboBox, _1);

当前代码失败,因为它试图调用 CComboBox::AddString(category)。这显然是错误的。如何使用当前语法调用 CComboBox::AddString(category.GetName())

最佳答案

std::for_each(categories.begin(), categories.end(), boost::bind(&CComboBox::AddString, &comboBox, boost::bind(&Category::GetName, _1)));

关于c++ - 如何使用 std::for_each 和 boost::bind 在参数上调用成员函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3760089/

相关文章:

c++ - 如何使用 Visual Studio 2013 构建 Boost 1.55?

c++ - 获取找到给定选项的 INI 文件行号的跨平台方法

C++继承模板类: hidden member variable

c++ - 代码已退出-1073741515(0xc0000135) 'A dependent dll was not found'

c++ - 多指针 X (MPX) 支持

visual-studio-2008 - ReflectedDefinition 属性的问题

c++ - 清理cpp中的密码字符串

c++ - 允许共享库中 undefined reference 的 g++ 标志是什么?

c++ - 在已编译的可执行文件中增加或指定间隙到 .text 部分以手动添加汇编代码

visual-studio-2008 - 我应该使用 vs2008 中的内置工具进行单元测试吗?