Originally Posted by
whiteflags
But it won't get to that.
well I need to make a local copy of rex for the function to use, so I call the copy constructor again, I need to make a local copy of rex for the function to use, so I call the copy constructor again, I need to make a local copy of rex for the function to use, so I call the copy constructor again, I need to make a local copy of rex for the function to use, so I call the copy constructor again ... seems like a problem!
hello wflags.
yep, I know it causes a recursion if I pass the object by value instead of passing the reference. You are giving me the same answer tabstops did and every other forum page has.
But they neglect to explain <b>why</b> it is happening.
yes, when you do this
void fido(rex)
the compiler needs to make a local copy of rex for the fido function to use. So it calls a copy constructor to copy the members to the new rex object (the copied object)
so this copy constructor is called, the one we've defined(the one we "know" to be wrong)
Code:
Dog(Dog a )
{
dog = a.weight ;
}
fine it has called the copy constructor, how does the C ctor call itself again? The compiler has made a local copy once, why would it need to make another copy again.
I feel like I am going nowhere