Most often it doesn't matter whether you use member initializer lists or assignments inside the body of your constructor. For example in your case you can perform the initialization of your int members from both the initializer list and the body of your constructor. However sometimes you can intialize a member only from the initializer list, and sometimes you HAVE TO explicitly initialize some members in the initializer list if you don't want to get a compile error!
class class_with_default_ctor
{
public:
class_with_default_ctor(int _i=0)
: i(_i)
{}
int i;
};
class class_without_default_ctor
{
public:
class_without_default_ctor(int _i)
: i(_i)
{}
int i;
};
class something
{
};
class test
{
public:
test(something& sg)
: m_class_with_default(5)
, m_class_without_default(6)
, m_const_int(7)
, m_const_something_ref(sg)
, m_something_ref(sg)
{
}
private:
class_with_default_ctor m_class_with_default;
class_without_default_ctor m_class_without_default;
const int m_const_int;
const something& m_const_something_ref;
something& m_something_ref;
};
You also HAVE TO use the initializer list to initialize a base class that doesn't have a default constructor if you don't want a compile error and you may want to use it to execute something else than the default ctor of the base class (same as with the member variables).