bind2nd and a const reference.
I'm trying to use the for_each(), bind2nd(), mem_fun() combination
below to perform a for loop, but I get the compiler warnings and error
below.
If I replace the Update( const T& hint ) function with Update( T
hint ), everything compiles just fine. Or, if I replace the for_each()
loop with a for() loop, everything works.
Why doesn't the for_each() loop work with the constant-reference
version of the update function?
std::list< myclass* > mylist;
void SomeFunc( const T& in )
{
// errors
std::for_each( mylist.begin(),
mylist.end(),
std::bind2nd( std::mem_fun( &myclass::Update ),
in ) );
// This works
std::list< myclass* >::iterator it( mylist.begin() );
for( it; it != mylist.end(); ++it )
{
( *it )->Update( in );
}
}
class myclass
{
void Update( const T& hint )
{
}
void Update2( T hint )
{
}
}
Warning 1 warning C4181: qualifier applied to reference type; ignored
C:\Program Files\Microsoft Visual Studio 8\VC\ce\include\functional
312
Warning 2 warning C4181: qualifier applied to reference type; ignored
C:\Program Files\Microsoft Visual Studio 8\VC\ce\include\functional
312
Error 3 error C2529: '_Right' : reference to reference is illegal C:
\Program Files\Microsoft Visual Studio 8\VC\ce\include\functional 312
Thanks,
PaulH