Initializing an object to all zeroes

后端 未结 12 639
离开以前
离开以前 2020-12-03 01:27

Oftentimes data structures\' valid initialization is to set all members to zero. Even when programming in C++, one may need to interface with an external API for which this

12条回答
  •  难免孤独
    2020-12-03 02:19

    I think the initialization speaks much clearer what you actually are doing. You are initializing the struct. When the new standard is out that way of initializing will get even more used (initializing containers with {} is something to look forward to). The memset way are slightly more error prone, and does not communicate that clearly what you are doing. That might not account for much while programming alone, but means a great deal when working in a team.

    For some people working with c++, memset, malloc & co. are quite esoteric creatures. I have encountered a few myself.

提交回复
热议问题