I am asking this question because if auto can identify the type of the value by itself so why we do not use auto all the time. I have just known about auto and I am really curious to know. Is it something related to the memory of auto?
Asked
Active
Viewed 188 times
0
-
Does this answer your question? [C++ auto keyword. Why is it magic?](https://stackoverflow.com/questions/7576953/c-auto-keyword-why-is-it-magic) – Kfir Ventura Apr 21 '21 at 05:53
-
For the issue on when and when not to use `auto`, see [How much is too much with C++11 auto keyword?](https://stackoverflow.com/questions/6434971/how-much-is-too-much-with-c11-auto-keyword) – mediocrevegetable1 Apr 21 '21 at 05:55
-
For non-argument variable definitions, `auto` can't be used unless you initialize the variable as then there's nothing to deduce the type from. – Some programmer dude Apr 21 '21 at 05:55
-
1There is an idiom in C++ called "almost always auto" that advocates just that: You should use auto as much as and where possible. – Casey Apr 21 '21 at 05:56
-
1Not using *always* `auto` improve compiler checks and most importantly improve readability of the C++ source code: too many `auto` in a source code makes it unreadable – Basile Starynkevitch Apr 21 '21 at 06:00
-
`so why we do not use auto all the time` that is opinion-based. Some advocate the AAA Style (Almost Always Auto) style like Herb Sutter ([GotW #94 Solution: AAA Style (Almost Always Auto)](https://herbsutter.com/2013/08/12/gotw-94-solution-aaa-style-almost-always-auto/)), you can also search for some cppcon talks of him. Others argue against it due to readability. – t.niese Apr 21 '21 at 07:11