【发布时间】:2013-01-21 17:13:19
【问题描述】:
我想从具有此类字符串作为属性的类列表中填充一组字符串(公共 getter 可用)。
我想使用 lambda 表达式和 std::for_each 来实现。
我正在考虑类似的事情:
class Foo
{
const std::string& getMe() const;
}
...
std::list<Foo> foos; // Let's image the list is not empty
std::set<std::string> strings; // The set to be filled
using namespace boost::lambda;
std::for_each(foos.begin(), foos.end(), bind(
std::set<std::string>::insert, &strings, _1::getMe()));
但是,我在编译时收到此错误:
_1 不是类或命名空间
谢谢。
【问题讨论】:
-
是的,你没有解释你有什么问题,如果有的话
-
@andy_t 只是想知道这是否可行,因为我没有直接插入 _1 占位符,而是在其上调用方法。
-
@AndyT :是的,我有一个编译错误(在问题中添加了它)。干杯。