Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) auto

 

auto is a keyword that has different meanings, depending on the standard used:

 

 

 

 

 

C++11 auto in the C++11 standard

 

In the C++11 Standard, auto is useful to let the compiler determine a variable's data type

 

 

 

 

 

C++98 auto in the C++98 standard

 

auto as described in the ISO/IEC 14882:2003 C++ Standard is a keyword to specify that a locally declared variable is destroyed at the end of its scope. In other words: to specify to do, what already will be done. In C++98, never write auto [1]

 

 

 

 

 

 

Example

 

 

 

 

 

 

Advice

 

 

 

 

 

 

References

 

  1. Herb Sutter. Exceptional C++ style. 2005. ISBN: 0-201-76042-8. Item 28 guideline: 'Never write auto'.
  2. Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 31.6. Advice. page 924: '[17] Use auto to avoid verbosity and typos when you use iterators'
  3. Scott Meyers. C++ And Beyond 2012 session: 'Initial thoughts on Effective C++11'. 2012. 'Prefer auto to Explicit Type Declarations'
  4. Scott Meyers. C++ And Beyond 2012 session: 'Initial thoughts on Effective C++11'. 2012. 'Remember that auto + { expr } == std::initializer_list'
  5. Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 6.6. Advice, page 169: '[20] Prefer the = syntax for the initialization in declarations using auto'

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict