Sign in to follow this  
bjogio

std::mem_fun_ref problem

Recommended Posts

Currently I'm working in a big project. Now I find that the stdlib have not a mem_fun2_t and I need it. I've considered using the boost::mem_fn but it's too complicate for my needs. So I decided to write a little adaptor classes by myself. I got a bunch of compiler error (using vc2003). I've isolated the problem in this little program:
#include <vector>
#include <functional>
#include <algorithm>
#include <iostream>

struct foo
{
   void bar(int a) { std::cout << a; }
};

int main( )
{
   std::vector<int> v(2);
   v[0] = 0;
   v[1] = 1;

   std::for_each(v.begin(), v.end(), std::mem_fun_ref(&foo::bar));
}

WHY on hell this program gives me C2064? This is driving me nuts. Sorry for my incompetence and my poor english. Thanks in advance

Share this post


Link to post
Share on other sites
You can't use std::mem_fun_ref() as the function object for for_each if the iterator range you are using is of primitive type. That is to say an int is not a foo, so you can't call &foo::bar on the int.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this