C++ auto keyword. Why is it magic?

From all the material I used to learn C++, auto has always been a weird storage duration specifier that didn’t serve any purpose. But just recently, I encountered code that used it as a type name in and of itself. Out of curiosity I tried it, and it assumes the type of whatever I happen to assign to it!

Suddenly STL iterators and, well, anything at all that uses templates is 10 fold easier to write. It feels like I’m using a ‘fun’ language like Python.

Where has this keyword been my whole life? Will you dash my dreams by saying it’s exclusive to visual studio or not portable?

8 Answers
8

Leave a Comment