GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Tech FAQs  >  OOPS

 Print  |  
Question:  Why the copy constructor is having a (&) variable as parameter?



November 11, 2007 07:39:54 #1
 vedjai   Member Since: November 2007    Total Comments: 1 

RE: Why the copy constructor is having a (&) variable as parameter?
 
the work of the copy constructor is to create a new object of the same class and copy the value of the data members from the calling object into this new object data members. When we pass some variables as input parameters, the copy constructor gets called to create local copies of the objects. If the & is ignored then the Copy Constructor will keep calling itself and will go into an endless loop. To avoid this endless loop situation, we have to pass the parameter into the copy constructor as a reference.
     

 

Back To Question