c++ - Best way to initialize class members? -


using c++11 standard, can initialize class members in 2 ways:

class myclass { private:      int = 5; }; 

or

class myclass { private:      int a; public:     myclass()     {         = 5;     } }; 

is either method superior other reason, or more individual style choice?

the second example not initialisation.

so, of 2 examples, first best way initialise class members.

the traditional way initialise looks this:

class myclass { private:      int a; public:     myclass()       : a(5)     {} }; 

though have inline initialisers in first example, since c++11.


Comments