Sign in to follow this  
wanzi

Yet another boost lambda question

Recommended Posts

For the following code, why (*) doesn't work?
using namespace std;
using namespace boost::lambda;
string p1("Hello");
string p2("World");
string s = (_1 + _2)(p1, p2);    // can't compile(*)
bool b = (_1 < _2)(p1, p2);    // compile, and b == true


Share this post


Link to post
Share on other sites
Ok, just found a solution, because expression (_1 + _2)(p1, p2) returns a value(string), ret<string> needs to be in front of the expression:

string s = ret<string>(_1 + _2)(p1, p2);

Why the compiler can't deduce the return type?

And why the (_1 < _2)(p1, p2) works? Is that because the return type is unknown, so int is assumed?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this