Jump to content
  • Advertisement
Sign in to follow this  
JimPrice

boost::shared_ptr and std::mem_fun (SOLVED)

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

Does anyone know of a way to get this to work:
typedef std::vector<boost::shared_ptr<Entity> > theEntitiesTypedef_;
theEntitiesTypedef_ theEntities_;

	std::for_each(
		theEntities_.begin(),
		theEntities_.end(),
		std::mem_fun(&Entity::Render));


Works fine if the container is a container of plain pointers to Entity; just breaks when I have a container of boost::shared_ptr's. I assume this is because there is no implicit conversion from boost::shared_ptr<T> to T*. Error message is: c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(21): error C2664: 'void std::mem_fun_ref_t<_Result,_Ty>::operator ()(_Ty &) const' : cannot convert parameter 1 from 'std::allocator<_Ty>::value_type' to 'Entity &' with [ _Result=void, _Ty=Entity ] and [ _Ty=boost::shared_ptr<Entity> ] Thanks, Jim. Edit : Ignore me, just found boost::mem_fn

Share this post


Link to post
Share on other sites
Advertisement
If I'm not mistaken, your problem is that you are trying to call an Entity function from a shared_ptr. On the up side, this means you probably won't need a member function, but a free function that calls Render from a passed shared_ptr.

EDIT: Actually, I'm not sure of shared_ptr's conversions either...

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!