可能重複:
What is this weird colon-member syntax in the constructor?
C++ initialization這是做什麼的? C++
我剛剛收到在C++程序中的頭文件,我想不通這行代碼的作用:
Card(Value faceValue=deuce, Suit suit = clubs):
suit(suit), faceValue(faceValue) {}
:
是什麼意思,爲什麼用;
替代它(我想我應該)破壞代碼?
對不起,這個問題的一般性,但有人可以解釋這兩行的目的嗎?
謝謝你的時間。
嗯...你能詳細闡述一下初始化列表嗎? –
@ spryno724閱讀[this](http://stackoverflow.com/questions/1711990/what-is-this-weird-colon-member-syntax-in-the-the-constructor) – Praetorian
@PhilipWhitehouse初始化之間有一個很大的區別初始化列表中的成員,並在構造函數的主體內執行。做後者意味着對象首先被默認構造,然後在主體內分配一些值。 – Praetorian