Can a object be passed as value to the copy constructor

后端 未结 6 2033
清歌不尽
清歌不尽 2021-01-12 18:56

I have some confusion with this \"Can a object be passed as value to the copy constructor\" The compiler clearly rejects this, which means it is not possible. Can you help m

6条回答
  •  情深已故
    2021-01-12 19:37

    No.

    As the error says, it will lead to recursive calls of the copy constructor. The copy constructor is used to copy an object. You need to make a copy of an object when it is passed by value.

    So, if you could have such a constructor, you would need to invoke the copy constructor to copy the object you pass to the copy constructor, ad infinitum.

提交回复
热议问题