在 4.14 http://eel.is/c++draft/conv.bool#1
它说:
A prvalue of arithmetic, unscoped enumeration, pointer, or pointer to member type can be converted to a prvalue of type bool.
为什么要特别强调右值?
算术类型的左值也可以转换为bool。
最佳答案
标准不希望 bool 值转换影响左值,因此不允许。
您当然可以将算术类型的左值转换为 bool
类型,但这不是通过(仅) bool 转换来完成的。将算术左值转换为 bool
是一个标准的转换序列,由 lvalue-to-rvalue 转换 和 boolean 转换组成。
关于c++ - 为什么bool转换明确提到prvalue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42266003/