天天看點

auto int b=0 不能與其他類型說明符組合

#include <iostream>
using namespace std;


int f(int a)
{
   // auto int b=0;//"auto"不能與任何其他類型說明符組合
	int b=0;
	static int c=3;
	b=b+1;
	c=c+1;
	return a+b+c;
}

int main()
{
	int a=2,i;
	for(i=0;i<3;i++)
		cout<<f(a)<<" ";
	cout<<endl;
	return 0;
}
           

用vs2010運作,出現錯誤提示:"auto”不能與任何其他類型說明符組合,因為新版C++定義auto不能和任何類型進行組合,直接寫作auto b=2,就表示把b自動轉換成整型,即auto根據後面的值自動把該變量轉換成相應的類型,或者不用auto,直接寫作int b=2,系統會自動預設為自動變量。

繼續閱讀