CConstructor Infinite Recursion!
Hi all!,
so I have finally reached the stage where I am "forced" to learn about Copy constructor. And i understand the basics of it.
When we pass an object by value as parameter, the Copy Constructor is called.
What I don't get is...how does it lead to an infinite recursion? Whereas pass by reference
doesn't ?
Code:
class Dog
{
Dog(){}
Dog(const Dog &dog)
{
//safe
}
Dog(Dog dog)
{
height=dog.height; //...
//leads to infinite recursion. But I don't see how!
}
}
how does the pass by copy lead to an infinite recursion ?
The copy constructor copies the all the member variables, does it copy the function code as well? , it copies them and pushes it onto the stack and it should stop.
Why would the copy constructor need to be called again, and again?
Can you please explain this to a noob.
Thanks.