Can a object be passed as value to the copy constructor

后端 未结 6 1943
清歌不尽
清歌不尽 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:18

    Though the answer was already given, I just wanted to clarify, since I see the same questions repeated. Dummy(Dummy dummy); is not a copy constructor. Copy constructor can either be of form Dummy(const Dummy&); or Dummy(Dummy&); The original one is clearly prohibited by the Standard.

    Then you are asking:

    Then why is it said that "Copy constructor will lead to recursive calls when pass by value is used."

    Diagnostic message is not mandated by the standard, rather your compiler chose those words to explain why it couldn't possibly work.

提交回复
热议问题