1

私は、C++ クラス コンストラクターが 2 つの異なる方法でメンバーを初期化するのを見てきましたが、効果は同じです。単純なクラスがあるとします:

class myClass
{
public:
    myclass();//default constructor

private:
    int a;
    int b;
    bool c;
};

ケース 1:

myClass::myClass()
/* Default constructor */
{
    a=5;
    b=10;
    c=true;

    //do more here
}

ケース 2:

myClass::myClass()
/* Default constructor */

    :a(5),
    b(10),
    c(true)
{
    //do more in here
}

コンパイル後の2つの違いは何ですか? 違いがなくても、「好ましい」方法はありますか?

4

1 に答える 1