No initializer list vs. initializer list with empty pairs of parentheses

前端 未结 2 979
难免孤独
难免孤独 2021-01-22 08:45

This is copy paste from this topic Initializing fields in constructor - initializer list vs constructor body

The author explains the following equivalence:



        
2条回答
  •  自闭症患者
    2021-01-22 09:11

    Your understanding is correct (assuming member1 and member2 have type `int). The two forms are not equivalent; in the first, the members are not initialized at all, and cannot be used until they have been assigned. In the second case, the members will be initialized to 0. The two formulations are only equivalent if the members are class types with user defined constructors.

提交回复
热议问题