久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

我可以在 for 循環(huán)的初始化中聲明不同類型的變量

Can I declare variables of different types in the initialization of a for loop?(我可以在 for 循環(huán)的初始化中聲明不同類型的變量嗎?)
本文介紹了我可以在 for 循環(huán)的初始化中聲明不同類型的變量嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

為什么這段 C++ 代碼在 VS2010 下無法編譯:

Why does this C++ code not compile under VS2010:

for ( int a = 0, short b = 0; a < 10; ++a, ++b ) {}

雖然這個是:

short b = 0;
for ( int a = 0; a < 10; ++a, ++b ) {}

是否禁止在for循環(huán)初始化器中聲明兩個不同類型的變量?如果是這樣,您如何解決它?

Is the declaration of two variables of different types inside the for-loop initializer prohibited? If so, how can you work around it?

推薦答案

是的,這是被禁止的.就像否則你不能在一個聲明語句中聲明不同類型的變量一樣(編輯:以@MrLister 提到的聲明符修飾符為模).您可以聲明結(jié)構(gòu)

Yes, that is prohibited. Just as otherwise you cannot declare variables of differing types in one declaration statement (edit: modulo the declarator modifiers that @MrLister mentions). You can declare structs

for (struct { int a = 0; short b = 0; } d; d.a < 10; ++d.a, ++d.b ) {}

C++03 代碼:

for (struct { int a; short b; } d = { 0, 0 }; d.a < 10; ++d.a, ++d.b ) {}

當(dāng)然,當(dāng)全部為0時,您可以完全省略初始化器并編寫= { }.

Of course when all are 0, you can omit the initializers altogether and write = { }.

這篇關(guān)于我可以在 for 循環(huán)的初始化中聲明不同類型的變量嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

What do compilers do with compile-time branching?(編譯器如何處理編譯時分支?)
Can I use if (pointer) instead of if (pointer != NULL)?(我可以使用 if (pointer) 而不是 if (pointer != NULL) 嗎?)
Checking for NULL pointer in C/C++(在 C/C++ 中檢查空指針)
Math-like chaining of the comparison operator - as in, quot;if ( (5lt;jlt;=1) )quot;(比較運算符的數(shù)學(xué)式鏈接-如“if((5<j<=1)))
Difference between quot;if constexpr()quot; Vs quot;if()quot;(“if constexpr()之間的區(qū)別與“if())
C++, variable declaration in #39;if#39; expression(C++,if 表達(dá)式中的變量聲明)
主站蜘蛛池模板: 在线观看亚洲欧美 | 日韩一级一区 | 色接久久 | 国产999精品久久久影片官网 | 久久国产成人 | 国产精品一区二区三 | 狠狠的操| 欧美成人高清 | 99国产精品99久久久久久 | 激情一区 | 国内精品久久精品 | 精品免费视频一区二区 | 国产一区二区三区四区三区四 | 久久久成人网 | 精品乱码一区二区三四区 | 亚洲精品一区二区三区在线 | 亚洲精品美女 | 亚洲高清三级 | 韩国成人在线视频 | 午夜免费观看体验区 | h片免费看 | 亚洲网一区 | www国产亚洲精品久久网站 | 天天干天天爱天天 | 亚洲一级黄色 | 欧美精品一区三区 | 欧美激情一区二区三级高清视频 | 亚洲国产精品一区二区三区 | 亚洲美乳中文字幕 | 日韩成人影院在线观看 | 日本欧美在线观看视频 | 国产成人一区二区三区 | 国产精品无码久久久久 | 国产一区二区 | 9久9久 | 亚洲成人av | 国产欧美精品一区 | 四虎影音| 一区二区久久 | 久久一区二区三区四区 | 欧美区在线观看 |