
Because you're passing a function pointer to bind() - but you didn't say which version of print_template you want to pass... I think you run into the same ambiguity with overloaded functions. -----Original Message----- From: Joe Van Dyk [mailto:joevandyk@gmail.com] Sent: Friday, July 28, 2006 11:23 AM To: boost@lists.boost.org Subject: Re: [boost] lamda question On 7/27/06, Joe Van Dyk <joevandyk@gmail.com> wrote:
On 7/27/06, Kevin Spinar <spinarkm@gmail.com> wrote:
On 7/27/06, Joe Van Dyk <joevandyk@gmail.com> wrote:
I have Boost 1.33.1 installed. I'm trying to use Boost.Lamda.
I included all the headers mentioned in the documentation as an attempt to fix the compile error.
#include <boost/lambda/lambda.hpp>
[snip unneeded includes]
#include <algorithm>
#include <list>
int main() { using namespace std; using boost::lambda;
list<int> v(10); for_each(v.begin(), v.end(), _1 = 1); }
% g++ lambda.cpp
you should compile with -W -Wall -pedantic -ansi at a minimum.
lambda.cpp: In function `int main()': lambda.cpp:20: error: `_1' undeclared (first use this function) lambda.cpp:20: error: (Each undeclared identifier is reported only once for each function it appears in.)
Using gcc 3.3.1.
Consider upgrading to gcc 4. With gcc 4, I get:
error: namespace 'boost::lambda' not allowed in using-declaration
Ah, thanks. I needed using namespace boost::lambda;
Joe
Another one: #include <iostream> #include <functional> #include <list> #include <algorithm> #include <boost/lambda/lambda.hpp> #include <boost/lambda/bind.hpp> using namespace std; template<class T> void print_template(const T& value) { cout << "value: " << value << endl; } void print(const int& value) { cout << "value: " << value << endl; } int main() { using namespace boost::lambda; list<int> v; v.push_back(3); v.push_back(4); v.push_back(5); for_each(v.begin(), v.end(), bind(print, _1)); // Works // Why doesn't this work? // for_each(v.begin(), v.end(), bind(print_template, _1)); } _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost