c++ - min_element() within template class -


i'm trying build home-made min-heap template class can work on dijkstra or prim. find_min() function not work std::min_element(). clue appreciated. thanks!

the error message vc2010express, in short, says

error c2780: '_fwdit std::min_element(_fwdit,_fwdit)' : expects 2 arguments - 3 provided

and code below:

#ifndef min_heap_h #define min_heap_h//use (unsorted) vector , min() algorithm #include <vector> #include <algorithm> #include <functional> template <typename t> class minheap{     std::vector<t> c;//container     typedef typename std::vector<t>::iterator iterator;     bool compare_node(const t& lhs,const t& rhs) const {return lhs<rhs;}//define compare function nodes public:     minheap():c(){}//default constructor      inline void insert(t node){c.push_back(node);}      iterator find_min(){         iterator min_node=std::min_element(c.begin(),c.end(),compare_node);//doesn't build         return min_node;     } //  deletemin(); //  deletenode(node); //  decreasekey(node); }; #endif 

std::min_element's 3rd argument either functor object, or function pointer comparator. comparator function must free function; you're trying give non-static member function.

as there no reason compare_node member function, may make free function instead.

having said that, compare_node equivalent implementation of default comparator std::min_element, may not use @ all.


Comments