【发布时间】:2011-02-05 11:26:05
【问题描述】:
我是 boost 新手。这是我的测试代码,
using namespace boost::lambda;
std::vector<std::string> strings;
strings.push_back("Boost");
strings.push_back("C++");
strings.push_back("Libraries");
std::vector<int> sizes;
std::for_each(
strings.begin(),
strings.end(),
bind(
&std::vector<int>::push_back,
sizes,
bind<std::size_t>(&std::string::size, _1)));
std::for_each(sizes.begin(), sizes.end(), var(std::cout)<<_1);
构建项目并产生错误:
错误 C2665: 'boost::lambda::function_adaptor::apply' : 2 个重载都不能转换所有参数类型
不知道怎么了?真的很感激。
【问题讨论】:
-
你想对向量中的字符串做什么?
-
bind 和 lambda 都有占位符
_1,bind 在匿名命名空间中,lambda 在 lambda 命名空间中。尽量不要使用整个 boost::lambda 命名空间
标签: c++ boost bind boost-lambda