Jump to content
  • Advertisement
Sign in to follow this  
fastcall22

[SOLVED] boost::mem_fn, boost::bind, std::remove_if problem

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

I'm experimenting with some complicated concepts that neither I nor my faithful C++ book have dared to touch. ;) Sorry if this sounds noob-ish, but it's my first time attempting to understand it. Here's an example of what I'm trying to do (based off the example code on boost.org)...
class ent_base
{
public:
	virtual bool step( const double &delta_time ) = 0;
	virtual void draw( const double &interpolate_factor ) = 0;
};

class game
{
private:
	boost::ptr_list<ent_base> m_objects;

public:
	void draw( const double &interpolate_factor )
	{
		// This is simple enough :)  Call draw(interpolate_factor) for each object
		std::for_each( m_objects.begin(), m_objects.end(), boost::bind( &ent_base::draw, _1, interpolate_factor ) );
	}

	bool step( const double &delta_time )
	{
		// This should work... :(  Call step(delta_time) for each object and remove it when the function returns true
		// Why doesn't this work? (C2582: 'operator =' is unavailable in 'ent_base')
		m_objects.erase( std::remove_if( m_objects.begin(), m_objects.end(), boost::bind( &ent_base::step, _1, dt ) ), m_objects.end() );			
	}	
};



The problem is, I don't know why it's trying to ent_base::operator=, and I don't think I want it to! _fastcall

Share this post


Link to post
Share on other sites
Advertisement
This comes from the nature of boost::ptr_list iterator, whose value type is ent_base instead of ent_base*. Since remove_if moves elements around through assignment, it will thus use ent_base::operator=.

To avoid this issue, use boost::ptr_list::erase_if.

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!