auto”不能与任何其他类型说明符组合小

来源:互联网 发布:淘宝卖家开不了花呗 编辑:程序博客网 时间:2024/06/10 19:08

环境:VS2010

代码:

#include <iostream>using namespace std;static int x = 10;void fun1()  {      x += 2;      cout << x << ", ";}void fun2() {    //auto int x = 11;//error C3530: “auto”不能与任何其他类型说明符组合    auto x = 11;    //int x = 11;    cout << x << ", ";}int main() {    //auto int x = 5;     auto x = 5;    //int x = 5;    cout << x << ", ";    fun1();    fun2();    cout << x << endl;getchar();}


问题:"auto”不能与任何其他类型说明符组合小结

总结:

1.新版C++定义auto不能和任何类型进行组合;

2.auto x = 14;表示把x自动转换成整型,归结为 auto 变量名 = 值(可以是基本数据类型):auto根据后面的值自动把该变量转换成相应的类型。

3.大多数以普通声明方式声明的变量都是auto变量,他们不需要明确指定auto关键字,默认就是auto;

4.auto变量在离开作用域是会被程序自动释放,不会发生内存溢出。

原创粉丝点击