Wednesday 22 February 2012

Is it possible to pass an object of the same class in place of object reference to the copy constructor? | Constructor in C++

 Yes, when an object is created without the reference formal argument, then the copy constructor is called for the argument object. The object that is passed as a parameter to the function is then passed as a parameter to the copy constructor.
For example:
 void xyz(A);
A A1;
xyz(A1);
void xyz(A A2)
{
//definition of xyz()
}
In this case, the copy constructor is called for A2 while Al is passed as a parameter to the copy constructor.