Default member values best practice

前端 未结 3 1869
一个人的身影
一个人的身影 2020-12-07 10:53

Is it good practice when writing C++11 code to set default values for class members in the header file of the class?

Or is it better to do this in the constructor of

3条回答
  •  太阳男子
    2020-12-07 11:35

    Initializing in headers has the main advantages of keeping code more local and easy to understand. It saves also some typing.

    The main disadvantage, in my opinion, is the need to include more headers to get access to constructors. Simple forward declaration won't suffice, making compilation take longer.

提交回复
热议问题