[EMCpp]Item-8 Prefer Nullptr to 0 and NULL
· ☕ 3 min read
nullptr doean’t suffer from the overloading problem or the template deduction problem that 0 and NULL are susceptible to. It also improves code clarity.
nullptr doean’t suffer from the overloading problem or the template deduction problem that 0 and NULL are susceptible to. It also improves code clarity.
Braced initialization is the most widely usable initialization syntax, which can also prevent narrowing conversions, as well as being immune to C++’s most vexing parse.
“Invisible” proxy types can cause auto to deduce the undesired type for an initializing expression, so we can adopt explicitly typed initializer idiom to force auto to deduce what we want.
Despite some pitfalls described in EMCpp item 2 and 6, auto variables are preferred for they must be initialized, are generally immune to type mismatches that can lead to portability or efficiency problems, can ease the process of refactoring, and typically require less typing than variables with explicitly specified types.
Deduced types can often be seen using IDE editors, compiler error messages, and the Boost TypeIndex library, but the results of some tools may be neither helpful nor accurate.