Jump to content
  • Advertisement
Sign in to follow this  

std::mem_fun_ref problem

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

If you intended to correct an error in the post then please contact us.

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!