Possible Duplicate:
Why should the copy constructor accept its parameter by reference in C++?
Why is copy constructor not allowed pass by value?
I am reading the lecture notes for my class on C++. In the notes they say the copy constructor signature for a class is
MyClass(MyClass &other)
and
MyClass(MyClass other)
won't work. Why is that?
Thank you!
Because MyClass(MyClass other) is passing the parameter by value, which itself requires a copy to be created. This would lead to an infinite loop (terminated only when your stack overflows).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With