Calling constructor from copy constructor

前端 未结 2 1244
礼貌的吻别
礼貌的吻别 2021-01-28 13:20

From c++ 11 we can call a constructor from another constructor. So instead of defining copy constructor can we call the constructor every time? Like in this piece of code :

2条回答
  •  一向
    一向 (楼主)
    2021-01-28 13:32

    So instead of defining copy constructor can we call the constructor every time?

    Yes, you can.

    Is there any ill effect to this approach? Is there any advantage of writing traditional copy constructor?

    Behavior-wise, there is no ill effect with your approach. With the member variables you have, IMO your approach is the most appropriate.

提交回复
热议问题