Copy Construction
Be careful when you see the value assignment symbol, because the "=" syntax can also be used to call the copy constructor.
For example:Widget W3 = W2; // call the copy constructor !!
The copy constructor is a particularly important function because it defines how an object is passed by value (passed by value ).
For example, considerCode:
Bool hasacceptablequality (widget W );
...
Widget awidget;
If (hasacceptablequality (awidget ))
...
The statement for decomposing hasacceptablequality (awidget) is as follows:
Widget W = awidget;
Hasacceptablequality (W)
The W parameter is passed to hasacceptablequality by value. In the preceding call, the widget is copied to the W body. This copy operation is completed by the copy constructor of the widget.
Conclusion: The pass-by-value in the function indicates "calling the copy constructor".
Passing user-defined types by value is usually a bad idea. pass-by-reference-to-const is usually a good choice.
Reprinted please note,ArticleFrom:Http://blog.csdn.net/windows_nt