std::sort std::vector predicate problem

M

mscava

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 T> T Polygon<T> ::
Height() const
{
class BinPred : public std::binary_function< Vector2D<T>,
Vector2D<T>, bool >
{
bool operator() ( Vector2D<T> rhs, Vector2D<T> lhs )
{
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() );
}
 
M

Marcus Kwok

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 T> T Polygon<T> ::
Height() const
{
class BinPred : public std::binary_function< Vector2D<T>,
Vector2D<T>, bool >
{
bool operator() ( Vector2D<T> rhs, Vector2D<T> lhs )
{
return rhs.Y() < lhs.Y;
}
};

IIUC local classes do not have external linkage and therefore cannot be
used as template arguments.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top