In C++11 onwards from what I understand from here and here is that if if I specify a member in the constructor's member initializer list and initialize it with an empty pair of parentheses it gets value-initialized. On the other hand, if I don't initialize a member in the member initializer list it gets default-initialized. If I understand things correctly this difference would matter for an int
member, for example, because default initialization would leave it in an indeterminate state. For members of class type I'm having a hard time understanding when default initialization could result in different behavior than value initialization. I see code where people:
- initialize class members with empty parentheses in the constructor's member initializer list
- don't explicitly initialize class members in the constructor
- initialize class members with a default member initializer of
{}
Is there ever a difference in effect here or can I just not think about choosing between how I initialize members?
Aucun commentaire:
Enregistrer un commentaire