I have a strange issue with std::less.
indexedpriorityq.hpp(21): error C2661: 'std::less<_Ty>::less' : no overloaded function takes 2 arguments
1> with
1> [
1> _Ty=float
1> ]
But isn’t that what it’s supposed to do?
Here’s some of my code:
template<class KeyType, class binary_predicate = std::less<KeyType> >
class IndexedPriorityQ
{
private:
typedef typename std::vector<KeyType> KEYLIST;
KEYLIST& m_Keys_V;
[...]
};
template<class KeyType, class binary_predicate>
void IndexedPriorityQ<KeyType, binary_predicate>::
ReorderUpwards(int size)
{
while( (size>1) &&
(binary_predicate(m_Keys_V[m_Heap_V[size]], m_Keys_V[m_Heap_V[size/2]])) //breaks here
)
{
Swap(size/2, size);
size /= 2;
}
}
What exactly is causing the error, and how can I fix it?
std::lessis a functor, and its constructor takes 0 arguments. That is, you create the objcet like this:Then, you use it like this:
or even
There are functors whose constructor takes more than 0 arguments, like
std::bind1st. The rule is that if the functor is binary, it is itsoperator()that takes 2 arguments.