Can the 'auto' keyword be used as a storage class specifier in C++11?

别说谁变了你拦得住时间么 提交于 2019-12-01 15:32:43
Prasoon Saurav

No the code is ill-formed in C++11. auto in C++11 would be used to deduce the type of a variable from its initializer and it can't be used as a storage class specifier.

Correct Usage

int main()
{
   auto x = 12; // x is an int
   auto y = 12.3; // y is a double
}
auto int x;

is circular - you are literally declaring the type as an int. given that you had this information - there is no reason to not simply use:

int x;

if you wanted to declare x the type of another variable in scope you can use decltype

using sometype = float;
sometype y;
decltype(y) x;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!