copy constructor with default arguments

前端 未结 2 517
灰色年华
灰色年华 2021-01-01 22:11

As far as I know, the copy constructor must be of the form T(const T&) or T(T&). What if I wanted to add default arguments to the signature

2条回答
  •  太阳男子
    2021-01-01 22:52

    Yes.

    §[class.copy]/2:

    A non-template constructor for class X is a copy constructor if its first parameter is of type X&, const X&, volatile X& or const volatile X&, and either there are no other parameters or else all other parameters have default arguments [ Example: X::X(const X&) and X::X(X&,int=1) are copy constructors.

提交回复
热议问题