Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

peter_b

calling a function in a std::binary_function, for std::list sort functor. gaaah :P

This topic is 5312 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

Hello! Im trying to sort my render list after the objects z-position. However, it seems it is not possible to call functoins from the arguments you send into a class that inherits from std::binary_function. Anyone know how to do this? Here is what i want to do, i have a class, gameobject. Which have a member, int zpos. But i want to call the member getZPos() instead of the variable. Because i do not want it to be public. Anyhow, this works:
//-----------------------------------------------------------------------------

// Name: SortByZPos

// Desc: 

//-----------------------------------------------------------------------------

struct SortByZPos : public std::binary_function<const Gameobject*, const Gameobject*, bool>
{ 
	result_type operator()( first_argument_type a, second_argument_type b ) 
	{
		return a->zpos > b->zpos;   
	}
};
This dosnt work: ( the return a->getZPos() > b->getZPos(); part)
//-----------------------------------------------------------------------------

// Name: SortByZPos

// Desc: 

//-----------------------------------------------------------------------------

struct SortByZPos : public std::binary_function<const Gameobject*, const Gameobject*, bool>
{ 
	result_type operator()( first_argument_type a, second_argument_type b ) 
	{
		return a->getZPos() > b->getZPos();   
	}
};
The error i get is:
error C2662: ''Gameobject::getZPos'' : cannot convert ''this'' pointer from ''const Gameobject'' to ''Gameobject &
And i cant see how to solve this.. is it some wierd syntax issue or is it just not possible? Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement

  • 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!