Received: by mail.email.jlu.edu.cn (Ecmail, from userid 99) To: Subject: helpdate: Sun, 10 Oct 2004 11:00:03 0800FROM: A Chaoyu Liang: Why copy constructor in C Why can't only be an object when only one parameter is, but must be referenced or pointers? Please help think. Going back is too rushing, too many legacy issues, I have not met, regret. I wish to find a job! Received: by mail.email.jlu.edu.cn (Ecmail, from userid 99) to: Subject: =? GB2312? Q? = D7 = aa = b7 = a2:? = DATE: TUE, 11 OCT 2004 00:10 : 57 0800FROM: ARM is this specified, and I think this is also reasonable, such as if there is such a value transfer copy constructor: Class Account {public: Account (Account RHS) {... }} During the execution of the copy constructor, since the value is passed, it is necessary to copy the RHS to generate a temporary object, and this copy is normal to call the copy constructor, so if the compiler does not make special The process will die. The copy constructor of the value passed, in my opinion, it is meaningless, so the compiler is not necessary to implement it. Received: by mail.email.jlu.edu.cn (Ecmail, From Userid 99) To: Subject: Re: Date: Mon, 11 Oct 2004 09:51:16 0800From: A super: copy constructor and assignment function system It is possible to automatically provide the default, there is no recursive situation, one of the proves is that if there is more than one parameter in the copy constructor (such as increasing an integer parameter), the value is allowed to pass. I see if I can understand: When multiple parameters have an overload, it is allowed, so the reference type parameters are allowed, while the reference type parameters of the system overwrite the default function of the system, value parameters, and the system's default function (reference type) Unable to distinguish, so it will not. Received: by mail.email.jlu.edu.cn (Ecmail, from userid 99) to: Subject: =? GB2312? Q? = D7 = aa = b7 = a2:? = DATE: TUE, 12 OCT 2004 00:10 : 35 0800FROM: Copy Constructor should be only a constructor of this type of parameter, or multiple parameters, the first is the constructor of this type and other default values. So if you add a parameter without the default value, the compiler will treat it as a general constructor instead of a copy constructor. Account (Account A, INT SALARY) {...} // is a general constructor, not a copy constructor account (Account A, int Salary = 0) {...} // it is a copy constructor, so It is still an error copy constructor to be used in the alignment of the equal number assignment and the functional value of the temporary object. At this time, in addition to being copied, it is impossible to give it an additional parameter, so it can't have a must be in more than one The form of parameters. After adding a parameter, it becomes a general constructor, and the copy of the parameter value is to call the true copy constructor. If it is not defined, it is called the default automatically generated copy constructor.
If you bring other default parameters, it is a copy constructor. If you really have the case of this type of value (the compiler is not limited) or call it yourself to copy, recursively loop until the memory consumption. Experiments can be done, prove Account (Account A, int Salary) is not a copy constructor, such as such statement Account A ("HAL9000", 1000); Account B = A; Nequate should be called copy constructor, but it will go Perform the default generated Copy CTOR instead of the one. There can only be a Copy Ctor in a class, or which one will be called when copying?