# std::mem_fun_ref problem

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

## 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 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.