469,926 Members | 1,561 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,926 developers. It's quick & easy.

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.

Similar topics

8 posts views Thread by lok | last post: by
7 posts views Thread by Ireneusz SZCZESNIAK | last post: by
6 posts views Thread by Jason Heyes | last post: by
4 posts views Thread by Johan | last post: by
10 posts views Thread by eiji | last post: by
5 posts views Thread by fade | last post: by
5 posts views Thread by jeremit0 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.