So, what just happened? The compiler used the values I initialized the variables with too set their type. Essentially, an auto variable that's type can be determined by the compiler.

There are some rules, however:

Auto variables have to be initialized to a value when they're created.

Auto variables can't have their types changed after initialization.

There are many uses for this in advanced and generic programming, however I'm going to talk about it's use for the beginning C++ programmer.

First off, I believe that using this for generic programming is fine, as clarified by Aardvajk.

The problem arises when beginning programmers want to be lazy and use these for everything. That is bad programming practice, and a lazy work ethic. You should know the types of your variables in your program, and using the auto variable because you don't want to memorize the names of the basic types defeats the purpose.

Now, where can I see myself using this variable? When I don't know the type of a variable I'm receiving. This generally doesn't happen very often unless you're dealing with generic programming, in which using this value is perfectly fine.

I also believe auto variables could be very confusing. If someone defines all their variables as auto variables, than I'll have no idea what the type of each variable is. This is especially noticeable in classes with an auto variable in them. If the variable is initialized in the constructor of the class, then I'd have to hunt through your code to find the type. This can be overcome by leaving a comment telling me what type the auto variable is, however that seem to defeat the purpose.

Having them initialized when they're created seems to defeat the purpose. They just seem like a tool for lazy programmers rather than a useful type of variable for making decisions at runtime.

Not really. They are extremely useful in template functions where the type is not actually known by the programmer.

The point is that auto is in no way intended to be for making decisions at runtime. It is compile-time resolved.

Not being able to change their types just reinforces the point above. It'd be better, for me, to be able to change the type of the variable rather than have it be set in stone when you create it.

If you want variables with types that can be changed at runtime, solutions exist (boost::variant, Qt's QVariant etc). Such features are better implemented as libraries than built into the language as there are a wealth of different ways to achieve this and there is no need for a core language feature.

Your class implementation could be much improved. Perhaps look at how some of the ones I mentioned above implement varadic types in C++.

Having them initialized when they're created seems to defeat the purpose. They just seem like a tool for lazy programmers rather than a useful type of variable for making decisions at runtime.

Not really. They are extremely useful in template functions where the type is not actually known by the programmer.

The point is that auto is in no way intended to be for making decisions at runtime. It is compile-time resolved.

Quote

Not being able to change their types just reinforces the point above. It'd be better, for me, to be able to change the type of the variable rather than have it be set in stone when you create it.

If you want variables with types that can be changed at runtime, solutions exist (boost::variant, Qt's QVariant etc). Such features are better implemented as libraries than built into the language as there are a wealth of different ways to achieve this and there is no need for a core language feature.

Your class implementation could be much improved. Perhaps look at how some of the ones I mentioned above implement varadic types in C++.

Changed, just now realized that if it has to be initialized in your code it's a compiler decision, not a runtime one. I'm going to stop making posts like these until I understand more now, and thanks for the corrections.

The type is automaticly deduced in a type-safe way at compile-time, since the compiler already knows what type myVector.begin() returns.When dealing with template metaprogramming, it gets far worse than the iterator example above.

Some of the people working on the standard language actually encourage people to use auto for every temporary variable.1) It makes the code easier to change later, making your code more flexible.2) auto never hides the type, it only grabs the type already specified by the right-hand side of the initialization.

When code-completion software is updated for C++11, it'll be just as easy as always to see what type a variable is, as the code-completion software needs to know the type anyway to properly offer suggestions for member vars and dereferencing, such as: "myAutoVar->...". So the code-completion will just let you hover your mouse over an auto variable and see what type it really is.

I think poorly named variables are more dangerous than auto, as auto only effects the declaration.