June 2025
Intermediate to advanced
1093 pages
33h 24m
English
In the condition of the if statement in Listing 16.8, I have hidden a little treat:
if(nullptr == db_) …
I compare nullptr and db_ with ==. I could just as well have written db_ == nullptr and achieved the same result. However, the order used has a big advantage.[ 39 ] If you accidentally type = instead of ==—which is something entirely different—then the compiler will point out the error: because nullptr is a literal, you cannot assign anything to it with =. If you had accidentally written db_ = nullptr, you would have unintentionally written an assignment. The assignment is also an expression, whose result here would then be nullptr—and nullptr is automatically converted to false by the compiler.
So if you implement ...
Read now
Unlock full access