Copy constructor [duplicate]
Possible Duplicate:
Why should the copy constructor accept its parameter by reference in C++? 开发者_运维知识库
Why the argument to a copy constructor is passed by reference?
If it is passed by value it would require making a copy using a...COPY CONSTRUCTOR. :-)
You can't pass it by value because pass-by-value implies making/passing a copy of the thing ... making a copy of the parameter passed to the copyy constructor would be recursive, cause a stack overflow.
As others have mentioned you can't pass it by value - because then you'd need a copy to create a copy!
The only other alternative would be to pass by pointer, but the syntax would require address-of, like so:
MyClass copy(otherclass); // by reference
MyClass copy(&otherclass); // by pointer
精彩评论