Boost logo

Boost Users :

From: Brian Braatz (brianb_at_[hidden])
Date: 2005-03-30 12:41:58


Ah Kindred spirits. I asked a similar question awhile ago (like last
year). I am sorry I was not able to find the original message.

 

The answer I was given was that the & is the correct syntax per the CPP
standard. What you are doing is taking the address of a memberfunction.

 

What was confusing to me was that some compilers allow you to LEAVE OFF
the & while others don't. The ones that do are trying to be helpful but
are not conformant.

 

 

________________________________

From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Sean DeNigris
Sent: Tuesday, March 29, 2005 7:31 PM
To: boost-users_at_[hidden]
Subject: [Boost-users] Boost.lambda

 

Can anyone explain why the class member functions need their address
taken when used in a boost::lambda::bind inside the class?

 

e.g.

vector<int> v;

MyClass theClass;

for_each(v.begin(), v.end(),

bind(MyClass::DoSomething, &theClass, _1));

 

//The above compiles fine, but...

 

class MyClass {

public:

            void DoSomething(const int& i) { ... }

            void Go()

{

for_each(myInts.begin(), myInts.end(),

/*--------------------->*/ bind(MyClass::DoSomething, this,
_1));

}

            vector<int> myInts;

};

 

The above code does not compile. The marked line needs to be:

bind(&MyClass::DoSomething, this, _1));

Why?

Thanks.

            - Sean

 

 



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net