No, they are not outdated, as in this article Check out the new C ++ 11 initialization formats in the initialization section of a class member (my attention):
Keep in mind that if the same data element has both a class member initializer and mem-init in the constructor, the latter takes precedence. In fact, you can take advantage of this behavior by specifying a default value for the member in the form of the initializer of the class member that will be used if the constructor does not have an explicit mem-init for this member. Otherwise, the mem-init constructor will take effect by overriding the initializer of the class member. This method is useful in classes with multiple constructors.
Thus, although initializing a class member is very convenient, it does not eliminate the need for initialization lists, but both functions work together to give you a good way to specify default values โโand override them when necessary. This is similar to how Bjarne Stroustrup sees it, he says:
This saves a bit of input, but the real benefits come in classes with multiple constructors. Often, for all constructors, a regular member initializer is used:
and provides an example of elements that share a common initializer:
class A { public: A(): a(7), b(5), hash_algorithm("MD5"), s("Constructor run") {} A(int a_val) : a(a_val), b(5), hash_algorithm("MD5"), s("Constructor run") {} A(D d) : a(7), b(g(d)), hash_algorithm("MD5"), s("Constructor run") {} int a, b; private: HashingFunction hash_algorithm;
and says:
The fact that hash_algorithm and s each has one default is lost in a mess of code and can easily become a problem during maintenance. Instead, we can eliminate the initialization of data members:
class A { public: A(): a(7), b(5) {} A(int a_val) : a(a_val), b(5) {} A(D d) : a(7), b(g(d)) {} int a, b; private: HashingFunction hash_algorithm{"MD5"};
Note: flaw in C ++ 11
There is one drawback of using a class member in initialization in C ++ 11, since it makes the class non-aggregate, we can no longer use aggregate initialization , which can be quite unexpected. This does not apply to C ++ 14, where this restriction has been removed. See Initializing C ++ 11 aggregates for classes with non-stationary element initializers for more details.