#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));
}
std::mem_fun_ref problem
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:
WHY on hell this program gives me C2064? This is driving me nuts. Sorry for my incompetence and my poor english. Thanks in advance
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement