C++: explicit specifier seems doesnt work when converting an object to boolean

C++: explicit specifier seems doesnt work when converting an object to boolean

I am learning c++ recently and I noticed an example on&nbsp;<a href="https://en.cppreference.com/w/cpp/language/explicit" target="_blank">cppreference</a>, part of which goes like this:

I am learning c++ recently and I noticed an example on cppreference, part of which goes like this:

struct B
{
    explicit B(int) { }
    explicit operator bool() const { return true; }
};

int main() { B b2(2); // OK: direct-initialization selects B::B(int) if (b2) ; // OK: B::operator bool() }

The introduction to implicit conversions tells me "when the expression is used in an if statement or a loop" the result of this expression( b2 ) will be converted into boolean type implicitly.

Also, the introduction to explicit specifier tells me if "a conversion function is explicit, it cannot be used for implicit conversions".

Since b2 will be converted implicitly in if(b2), and the conversion function is explicit, how comes if(b2) is ok?

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

C/C++ vs. Rust: A developer’s perspective

In this post, you'll see the difference between Rust and C/C++ in a developer’s perspective

Variable Introduction in C#[Bangla]

LIKE | COMMENT | SHARE | SUBSCRIBE A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C# has a speci...