Initializing multiset with custom comparison function in C++

前端 未结 4 1309
独厮守ぢ
独厮守ぢ 2021-02-04 14:50

Consider following comparison function:

bool compare(std::shared_ptr &lhs, std::shared_ptr &rhs){
   return lhs->val         


        
4条回答
  •  走了就别回头了
    2021-02-04 15:25

    The comparator passed to the template has to be the type of something that can be called with the function call operator. That would be either a class that has overloaded that operator, or the type of a lambda or a function pointer. In the cunstrutor of set, an instance of that type has to be passed. So decltype(compare)* is the function pointer type, and &compare is the function pointer.

提交回复
热议问题