1
做一個二十一點遊戲,並需要知道如何使用基本成員初始化來初始化一個數組(即使用一元範圍解析運算符在構造函數中進行初始化)。如何在數組上使用基本成員初始化?
//Constructor
Card::Card()
:mRank(static_cast<Rank>(ACE)), mSuit(static_cast<Suit>(SPADES)), mRankText(), mSuitText()
{
}
欲破爛陣列mRankText和mSuitText初始化到
const char * rankText[NUMBER_OF_RANKS] = {"Ace",
"Deuce",
"Trey",
"Four",
"Five",
"Six",
"Seven",
"Eight",
"Nine",
"Ten",
"Jack",
"Queen",
"King"};
const char * suitText[NUMBER_OF_SUITS] = {"Spades",
"Clubs",
"Diamonds",
"Hearts"};