【发布时间】:2020-09-05 13:15:12
【问题描述】:
我正在使用std::count_if() 遍历向量向量的每个“列”,并返回大于某个值且在某个“行范围”内的项目数。出于某种原因,我得到了错误:
note: candidate function not viable: no known conversion from 'std::vector<double, std::allocator<double> >' to 'double *' for 1st argument
引用 lambda 的第一个参数 coln。
我的代码(其中TO 和FROM 是某个整数,ROWS 是向量向量中的“行”数),这是一个类的内部方法:
vector<vector<double> > channels;
// Code to ill 'channels' with some data
for(int coln = 0; coln < _chnl; ++coln){
auto start = std::next(channels.begin(), FROM);
auto stop = std::prev(channels.end(), (ROWS-1) - TO);
return std::count_if(start, stop, [coln, threshold](double row[]){
return row[coln] > threshold;
});
}
另外请注意,我使用的是 Cling 解释器,但我也能够在 Clang 中重现错误。
【问题讨论】: