【问题标题】:Error " no known conversion from 'std::vector<double, std::allocator<double> >' to 'double *' " when using std::count_if()?使用 std::count_if() 时出现错误“没有从 'std::vector<double, std::allocator<double> >' 到 'double *' 的已知转换”?
【发布时间】:2020-09-05 13:15:12
【问题描述】:

我正在使用std::count_if() 遍历向量向量的每个“列”,并返回大于某个值且在某个“行范围”内的项目数。出于某种原因,我得到了错误:

note: candidate function not viable: no known conversion from 'std::vector&lt;double, std::allocator&lt;double&gt; &gt;' to 'double *' for 1st argument

引用 lambda 的第一个参数 coln

我的代码(其中TOFROM 是某个整数,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 中重现错误。

【问题讨论】:

  • 再一次,请您不要再向overover 发送同样的问题了吗?

标签: c++ vector stl


【解决方案1】:

你的 lambda 错误,应该是:

[coln, threshold](const std::vector<double>& row){ return row[coln] > threshold;}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-14
    • 2017-12-27
    • 2016-01-25
    • 2014-05-06
    • 1970-01-01
    • 2018-09-23
    • 2016-01-24
    • 1970-01-01
    相关资源
    最近更新 更多