Jump to content
  • Advertisement
Sign in to follow this  

[C++] vectorT sorting

This topic is 3011 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Looking at the example from here I am trying to add sorting for a vector<T> in a class but I am getting "error: '__comp' cannot be used as a function" In my class I have
class QuadManager {
	bool operator() (Quad3D* quad1, Quad3D* quad2) { return (quad1->Texture()->Id() < quad2->Texture()->Id()); }

	vector<Quad3D*>	m_quadArray;
Then in the class I try and sort
sort(m_quadArray.begin(), m_quadArray.end(), this);

Share this post

Link to post
Share on other sites
this is a pointer. Compare needs to be value type, since sort calls p() or p.operator(), not p->operator().

Solution would be to pass *this, but it is a very bad idea, since it is highly likely that one or more copies of compare object will be made.

Compare predicate is typically implemented as a standalone class.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!