Skip to main content
gamedev.net
🔒 Locked

Yet another boost lambda question

Started by wanzi 0 replies 1k views
Original Post
wanzi
wanzi
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


wanzi
wanzi
Ok, just found a solution, because expression (_1 + _2)(p1, p2) returns a value(string), ret needs to be in front of the expression:

string s = ret(_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?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.