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  >  Interview Questions  >  Programming  >  C++

 Print  |  
Question:  Difference between a "assignment operator" and a "copy constructor"



July 07, 2007 11:38:05 #3
 Indrajit Paul   Member Since: Visitor    Total Comments: N/A 

RE: Difference between a "assignment operator" and a "...
 
Inspite of repeated requests by some (few) sensible people to everybody to read the question properly before responding, nobody listens.

For doreen, the question does not ask you to explain deep copy and shallow copy mechanism neither does is asks how assignment operator should be written.

It asks the difference between a assignment operator and a copy constructor.

The difference is, a assignment operator (default or user provided) is called when the object already has been instantiated. A copy constructor is called when the object has not yet been constructed.

For Example.

Class A{/*...*/};

main()
{
   A a;
   A b = a; /* copy constructor will be called */
   A c;
   c = a; /* assignment operator will be called*/
}
     

 

Back To Question