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

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

## 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 on other sites
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...

• 9
• 9
• 13
• 41
• 15