On Wed, 2 Jun 2004 10:52:27 +0900, "ES Kim" <no@spam.mail> wrote:
Here's a simple code:
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
struct S
{
void f(int) const { }
void g(const int&) const { }
};
int main()
{
int n = 1;
vector<S> v;
for_each(v.begin(), v.end(), bind2nd(mem_fun_ref(&S::f), n));
for_each(v.begin(), v.end(), bind2nd(mem_fun_ref(&S::g), n));
}
What is the reason why the second for_each() doesn't compile?
This is the "reference-to-reference" problem; Scott Meyers discusses it in
Item #50 of _Effective STL_, where he mentions that the Boost library
provides alternate function objects to get around the problem. I haven't
played with them, but you may get lucky at
www.boost.org.
-leor
--
Leor Zolman --- BD Software ---
www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html