When C++11 introduced auto
, it opened up a whole range of useful techniques and improved the life of C++ developers in a variety of ways. There’s no shortage of simple examples and tutorials teaching how to start using auto
, but as is often the case, many of these well intentioned examples have left readers with an incomplete picture of how to use auto
effectively and in some cases have resulted in poor habits becoming common practice. Since auto
essentially hides away some of the details of how objects are created, there is a risk that developers don’t think as carefully about what is actually taking place. This article aims to arm the reader with information often omitted so that common pitfalls can be avoided.