469,926 Members | 1,561 Online

# std::sort std::vector predicate problem

How can I make this construction valid? It still gives me error about
no matching function std::sort(...). I made a little search and wrong
thing is probably the predicate...

template <typename TT Polygon<T::
Height() const
{
class BinPred : public std::binary_function< Vector2D<T>,
Vector2D<T>, bool >
{
bool operator() ( Vector2D<Trhs, Vector2D<Tlhs )
{
return rhs.Y() < lhs.Y;
}
};

// vertices_ is structure already filled with Vector2D's
std::vector< Vector2D<T tmp = vertices_;
std::sort( tmp.begin(), tmp.end(), BinPred() );

return std::abs( tmp.front().Y() - tmp.back().Y() );
}

Apr 6 '07 #1
1 4967
ms****@gmail.com wrote:
How can I make this construction valid? It still gives me error about
no matching function std::sort(...). I made a little search and wrong
thing is probably the predicate...

template <typename TT Polygon<T::
Height() const
{
class BinPred : public std::binary_function< Vector2D<T>,
Vector2D<T>, bool >
{
bool operator() ( Vector2D<Trhs, Vector2D<Tlhs )
{
return rhs.Y() < lhs.Y;
}
};
IIUC local classes do not have external linkage and therefore cannot be
used as template arguments.
// vertices_ is structure already filled with Vector2D's
std::vector< Vector2D<T tmp = vertices_;
std::sort( tmp.begin(), tmp.end(), BinPred() );
See above. Also, make sure you #include <algorithm>.
return std::abs( tmp.front().Y() - tmp.back().Y() );
}
--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Apr 6 '07 #2

### This discussion thread is closed

Replies have been disabled for this discussion.