So when a user usually creates a copy constructor for a class he uses a reference: X(X&)
But why? Why a reference and not a value? I know that the reference way is cheaper and faster but still,there must be some other explanation.
So when a user usually creates a copy constructor for a class he uses a reference: X(X&)
But why? Why a reference and not a value? I know that the reference way is cheaper and faster but still,there must be some other explanation.
Because having value instead of reference/pointer in any function creates a copy of the class object. Which constructor are we overloading again?
(In case you need further explanation: As we pass X by value, this would create a copy which would invoke the copy constructor - which would create another copy, also invoking the copy constructor, and so on...)