可以在C ++ 11中将'auto'关键字用作存储类说明符吗? [英] Can the 'auto' keyword be used as a storage class specifier in C++11?

查看:100
本文介绍了可以在C ++ 11中将'auto'关键字用作存储类说明符吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

auto关键字可以用作C ++ 11中的存储类说明符吗?

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

以下代码在C ++ 11中合法吗?

Is the following code legal in C++11?

int main() {
   auto int x;
}

推荐答案

C ++ 11中的代码格式不正确. C ++ 11中的auto将用于从其初始值设定项推导变量的类型,并且不能将其用作存储类说明符.

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.

正确用法

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

这篇关于可以在C ++ 11中将'auto'关键字用作存储类说明符吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆