我想使用 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/