C++ (error: passing ‘const …'’ as ‘this’ argument of ‘…’ discards qualifiers [duplicate])

来源:互联网 发布:spring web flow 知乎 编辑:程序博客网 时间:2024/06/11 13:33

Ubuntu下编译GCC编译caffe,出现error

c++/4.8/bits/stl_algo.h:2245:19:     error: passing const yolo_v2::DATA as  this  argument of  bool yolo_v2::DATA::operator<(yolo_v2::DATA)  discards qualifiers [-fpermissive]
    while (__pivot < *__last)

大致的意思就是:将非变量传递的类型不一致导致错误

作者代码:

 bool operator<( DATA data)        {            return this->confidence > data.confidence;        }

定位到STL的源码:

/// This is a helper function...  template<typename _RandomAccessIterator, typename _Tp>    _RandomAccessIterator    __unguarded_partition(_RandomAccessIterator __first,  _RandomAccessIterator __last, const _Tp& __pivot)    {      while (true){  while (*__first < __pivot)    ++__first;  --__last;  while (__pivot < *__last)    --__last;  if (!(__first < __last))    return __first;  std::iter_swap(__first, __last);  ++__first;}    }
解决方案:(链接:https://stackoverflow.com/questions/19073996/error-passing-const-as-this-argument-of-discards-qualifiers)

bool operator<(const DATA& data) const        {            return this->confidence > data.confidence;        }


阅读全文
0 0
原创粉丝点击