I am moving towards C++11 from C++98 and have become familiar with the auto
keyword. I was wondering why we need to explicitly declare auto
if the
auto
is a keyword which you can use in places where you normally need to specify a type.
int x = some_function();
Can be made more generic by making the int
type automatically deduced:
auto x = some_function();
So it's a conservative extension to the language; it fits into the existing syntax. Without it x = some_function()
becomes an assignment statement, no longer a declaration.