lundi 27 août 2018

C++ Constructor Direct Initialization [duplicate]

This question already has an answer here:

I suppose we can initialize class members from constructor arguments this way:

class Foo {
public:
    Foo(int x, int y)
        :mos(x), som(y) { }
private:
    int mos;
    int som;
};

But I wonder whether we can do it this way as well (and whether there's any difference, if at all):

class Foo {
public:
    Foo(int x, int y)
        :mos{x}, som{y} { } // mos{x} instead of mos(x)
private:
    int mos;
    int som;
};

Thanks.

Aucun commentaire:

Enregistrer un commentaire