Possible Duplicate:
How much is too much with C++0x auto keyword
The new keyword “auto”; When should it be used to declare a variable type?
In C++11, Typing a variable auto instead of, say, int, will let the compiler automatically use the right type, deduced from its initialization context. This comes super handy in situations where the type is obvious but boring to write. Are there pitfalls to be aware of, or reasons why someone would avoid using that?
My personal experience is auto is handy for generic code, or things like range-based for loop, but you might get something like
auto count = getCount();
if (count < 0) {
// do something
}
If getCount() returns an unsigned number, instead of what you might be expecting (int), you won't even get a warning.
来源:https://stackoverflow.com/questions/8430053/is-c11-auto-type-dangerous