It's a typo in the book. Look at Errata for 2nd and 3rd printings of The C++ Programming Language. The example must be like below:
auto z3 =[y]() { return (y) ? 1 : 2; }
Looks to me like a simple typo. Should probably be:
auto z3 =[y]() { return y ? 1 : 2; }
Note that since the lambda doesn't take any parameters, the parens are optional. You could use this instead, if you preferred:
auto z3 =[y] { return y ? 1 : 2; }
return 1 : 2;
is a syntax error, it is not valid code.
A correct statement would be more like return (y) ? 1 : 2;
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With