Optimization due to constructor initializer list

后端 未结 8 1761
故里飘歌
故里飘歌 2020-12-13 21:23

Constructors should initialize all its member objects through initializer list if possible. It is more efficient than building the constructors via assign

8条回答
  •  醉梦人生
    2020-12-13 22:16

    Because it initialises directly, instead of default initialising and then assigning. It likely won't matter performance-wise for PODs, but it will if the type constructor is doing heavy-weight work.

    Also, in some cases you must use init list, so you should always do it for consistency.

提交回复
热议问题