0

以下は、完全には理解できない初期化リストのコードです。特に、ページの最後の部分です ( red(Bow("red")) and blue(Bow("blue"))。

.hBow は、形式のコンストラクタを持つファイルに含まれる別のクラスBow(string aColor)です。

初期化構文は次のとおりです。

ClassName(argumentlist): datamember1(value1), dataMember2(value2){}

この初期化の仕組みがわかりません。Bowclassで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)**
{
}
4

6 に答える 6

1

初期化子

red(Bow("red"))

Bow引数「red」でコンストラクターを呼び出し、redその new (anonymous) で初期化しBowます。

于 2013-06-18T05:30:48.370 に答える
0

Bow("red")class のインスタンスを提供しますBow

red(Bow("red"))で日付メンバーredを初期化することを意味しますBow("red")

于 2013-06-18T05:31:26.717 に答える