Why should the copy constructor accept its parameter by reference in C++?

前端 未结 8 1306
离开以前
离开以前 2020-11-22 17:00

Why must a copy constructor\'s parameter be passed by reference?

8条回答
  •  迷失自我
    2020-11-22 17:46

    It is necessary to pass object as reference and not by value because if you pass it by value its copy is constructed using the copy constructor.This means the copy constructor would call itself to make copy.This process will go on until the compiler runs out of memory.

提交回复
热议问题