std::mem_fun_ref problem

Started by
1 comment, last by bjogio 18 years, 6 months ago
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
[ILTUOMONDOFUTURO]
Advertisement
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.
oh thanks a lot. Stupid me...
[ILTUOMONDOFUTURO]

This topic is closed to new replies.

Advertisement