【发布时间】:2013-08-27 13:21:48
【问题描述】:
在 MSVC 2012 中:
const std::string tableString;
std::vector<size_t> trPosVec;
// other stuff...
std::for_each(trIterator, endIterator,
[&, tableString, trPosVec](const boost::match_results<std::string::const_iterator>& matches){
trPosVec.push_back(std::distance(tableString.begin(), matches[0].second));
}
);
此代码给出了工具提示错误:
Error: no instance of overloaded function "std::vector<_Ty, _Alloc>::push_back [with _Ty=size_t, _Alloc=std::allocator<char32_t>]" matches the argument list and object (the object has type qualifiers that prevent a match)
argument types are: (ptrdiff_t)
object type is: const std::vector<size_t, std::allocator<char32_t>>
我的意思是它按值捕获trPosVec。当我明确指定捕获模式[&tableString, &trPosVec] 时,它工作正常。如果我尝试像[&, tableString, &trPosVec] 那样双重指定,它会给出Error: explicit capture matches default. 这是怎么回事?
【问题讨论】:
标签: c++ visual-c++ c++11 lambda