   [C++] std::bind and std::ref
  Hello,I am experimenting a bit with the recently release visual studio 2010. This piece of code is giving me compile errors:#include <iostream>#include <functional>using namespace std;struct A{   void memFunc( int i )   { cout << "memFunc\n";   }};int main(){   { A a; auto func = bind( &A::memFunc, ref(a), 6 ); func();   }}error C2100: illegal indirectionerror C2440: 'newline' : cannot convert from 'std::tr1::reference_wrapper<_Ty> *' to 'A *'error C2647: '.*' : cannot dereference a 'void (__thiscall A::* )(int)' on a 'std::tr1::reference_wrapper<_Ty>'All these errors are found at c:\program files\microsoft visual studio 10.0\vc\include\xxpmfcaller:30If I replace the ref(a) part with just a or &a it works. With equivalent code using boost I used to be able to use boost::ref().Doing:cout << typeid(bind( &A::memFunc, ref(a), 6 )).name() << endl; compiles and executes fine so I am guessing that while copying/assigning the resulting bind expression there is a problem with copying the reference wrapper?Can someone tell me if what I'm doing is wrong, or if there is some compiler error in vs2010? (Which is still beta after all so it's possible :) )   
  AFAIK that "should" work -- but I'm guessing it has more to do with invocation than assignment.  Does bind( &A::memFunc, ref(a), 6 )(); work?As a hackaround, you should be able to replace ref(a) with &a and have it work. Wow I should learn to read.[Edited by - MaulingMonkey on June 15, 2009 1:21:01 PM];  bind( &A::memFunc, ref(a), 6 )(); gives the same errors.This works:void freeFunc( A& a, int i ){   a.memFunc( 4 );}auto func = bind( &freeFunc, ref(a), 9 );but this gives the same errors:auto func = bind( mem_fn(&A::memFunc), ref(a), 8 );Ah well, I'll try again when it is not in beta. I know the workaround, I am just playing with the new features. I estimate it will be 2020 before my company starts using a c++0x(*) compliant compiler anyway :)(*) I keep forgetting how to make a plus character in this forumedit: ok now I remember :)[Edited by - Icon on June 15, 2009 3:02:57 PM];  You know, I ran into something real similar in VS2008ee.The function definitions for std::mem_func() didn't have overloads to work with references.;Quote:Original post by Icon(*) I keep forgetting how to make a plus character in this forumJust type them.  The show preview is buggy -- they won't appear in it, but they'll still appear in the final post.   ;  Ok it is a bug. I sent an email to the person in charge of the stl at microsoft. He replied and confirmed that it looks like a bug. I am really impressed with microsoft lately. As far as I can see they are doing a good job, going out of their way to help us developers. (I am in no way affiliated with microsoft :))He also gave me the advice to use lambdas instead of bind, I agree they are much better and easier than bind.   