[EMCpp]Item-9 Prefer Alias Declarations to Typedefs
· ☕ 2 min read
Alias declaration support templatization, which avoids the “::type” suffix and “typename” prefix often required to refer typedef
s.
Alias declaration support templatization, which avoids the “::type” suffix and “typename” prefix often required to refer typedef
s.
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.