Compile error using boost's tr1::bind

This code:
#include <iostream>
#include <algorithm>
#include

What is needed for the code to compile and run properly?
Which Boost version and is Boost installed in /usr/include or somewhere similar? Basically this is a known problem for some Boost versions when Boost is installed in your *system search path* - the issue is that the Boost headers are in a location that is searched *after* the libstdc++ headers and that breaks the header-forwarding mechanism used by Boost.TR1. The solution is probably to upgrade to the latest Boost release, or if all else fails, the SVN Trunk. HTH, John.

Tron Thomas: ...
int main() { Value sum; int values[] = { 1, 2, 3, 4, 5 }; std::for_each(values, values + 5, std::tr1::bind(&Value::IncreaseBy, sum)); std::cout << "The value is " << sum << std::endl; return 0; }
You need to use std::for_each(values, values + 5, std::tr1::bind(&Value::IncreaseBy, &sum, _1)); &sum (or, if you prefer, std::tr1::ref(sum)) is needed so that bind doesn't make a copy of sum. The _1 is needed to receive the number from values and pass it to IncreaseBy as the 'amount'.
participants (3)
-
John Maddock
-
Peter Dimov
-
Tron Thomas