以下は、完全には理解できない初期化リストのコードです。特に、ページの最後の部分です ( red(Bow("red")) and blue(Bow("blue")
)。
.h
Bow は、形式のコンストラクタを持つファイルに含まれる別のクラスBow(string aColor)
です。
初期化構文は次のとおりです。
ClassName(argumentlist): datamember1(value1), dataMember2(value2){}
この初期化の仕組みがわかりません。Bow
classでclass のオブジェクトを作成することを理解していますArcheryCompetition
。別のクラスのコンストラクターが別のコンストラクターの初期化リストで呼び出されているようです。これはすべて、私が読んでいる初心者向けの本からのものです。
さらに明確にする必要がある場合は、お知らせください。
class ArcheryCompetition
{
//member variables
private:
//variables
int rounds;
float redScore;
Bow red;
float blueScore;
Bow blue;
public:
//constructor
ArcheryCompetition( int lrounds);
//destructor
~ArcheryCompetition();
//methods
int compete(void);
};
ArcheryCompetition::ArcheryCompetition(int lrounds):
rounds(lrounds), red(Bow("red")), blue(Bow("blue")), redScore(0), blueScore(0)**
{
}