Calling constructor from copy constructor

前端 未结 2 1243
礼貌的吻别
礼貌的吻别 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:39

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

    Yes, you can

    One of the advantages of delegating constructors is avoiding code duplication by having common initialization in some constructors that might require a full set of arguments.

    Is there any advantage of writing traditional copy constructor?

    The capability to do construction delegation is not related to the need of defining the copy constructor or any other special constructors. You need to define them if necessary.

提交回复
热议问题