Boost logo

Boost Users :

From: Robert Dailey (rcdailey_at_[hidden])
Date: 2007-11-27 18:32:12


I ended up using boost::bind() anyway lol.

Tick is a function called in my game every frame. Tick takes a float because
my game uses seconds as delta time. 1.0f is 1 second, 0.5f is half a second
and so on.

Thanks for your help.

On Nov 27, 2007 4:21 PM, Bill Buklis <boostuser_at_[hidden]> wrote:

> I can't figure out how to use std::mem_fun() and std::bind1st() with
> std::for_each() to call into a member function for each element in a
> boost::ptr_vector object. Some sample code below:
>
> class Object
> {
> public:
> void Tick( float number ) {}
> };
>
> boost::ptr_vector<Object> m_objects;
> using namespace std;
> for_each( m_objects.begin(), m_objects.end(), bind1st( mem_fun(
> &Object::Tick ), 5 ) );
>
>
> Of course, this doesn't compile at all. Can anyone tell me what I'm doing
> wrong?
>
>
>
> Try using boost::bind. It makes life so much simpler. Once I discovered
> that I never used bind1st, mem_fun, etc. again. I believe this is included
> in TR1 anyway.
>
>
>
> for_each( m_objects.begin(), m_objects.end(), boost::bind(&Object::Tick,
> _1, 5.0) );
>
>
>
> Although, this may give you a warning about converting a double to a
> float. Why is Tick defined to take a float anyway?
>
>
>
>
>
> -- Bill --
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net