An initialiser list is the preferred method for assigning values to data members in class constructors. For example:
Code:
// initialise members to zero / null
planet::planet() : weight(0), newweight(0){} // strings are default initialised to a null string
or:
Code:
// initialise members to supplied values
planet::planet(const std::string& p, int w, int n) : plan(p), weight(w), newweight(n){}
If you initialise data members in the body of a constructor, it means that they are first default constructed, then assigned to. An initialiser list is more efficient as they are both constructed and initialised at the same time. This method is mandatory if a data member is a constant.