Possible Duplicate:
Why should the copy constructor accept its parameter by reference in C++?
i know that a copy constructor must have a reference as a parameter, to avoid an ‘infinite number of calls’ to itself. my question is – why exactly that happens, what is the logic behind it?
CExample(const CExample& temp)
{
length = temp.length;
}
assume your argument to the copy C’tor was passed by value, the first thing the C’tor would have done, was copying the argument [that’s what every function, including constructors do with by-value arguments]. in order to do so, it would have to invoke the C’tor again, from the original to the local variable… [and over and over again…] which will eventually cause an infinite loop.