Programming: Practices and Principles - Bjarne StroustrupDrill in Ch 5 - ErrorsHe wants us to correct the code:boo c = fool<s;On correcting boo to bool, this is a comparison, so that's fine. c will be assigned either true or false. But if I edit it tobool c = fool;It also evaluates to true. Then I tried , 'd', 235, and they all evaluate to true. Shouldn't there be a type error? Narrowing conversion? Something? (I tried {} for checking narrowing conversions.)
bool accepts int literals, char literals, string literals - why?
c++
As can be found here, there is a conversion happening:Prvalues of integral, floating-point, unscoped enumeration, pointer, and pointer-to-member types can be converted to prvalues of type bool.The value zero (for integral, floating-point, and unscoped enumeration) and the null pointer and the null pointer-to-member values become false. All other values become true. 