Question:
what are the disadvantages of copy constructor??
Answer:
Well if we are talking about the default copy constructor, then the disadvantage it suffers from is that i does a shallow copy of the class object.<br>Which means that if the class has some dynamic memory allocated or file pointers, the copied object will also point to the same memory location or files. That is the memory or file is not copied. Source: CoolInterview.com
Answered by: Samit Sasan | Date: 10/22/2007
| Contact Samit Sasan
If the programer is defining the copy constructor, the compiler will invoke the copy constructor at the time of copying the members of the calling object to the members of the called objects. This will cretaes the problems if the object contains the pointer variables. The time copying is more if there are more number of object memebrs Source: CoolInterview.com
Answered by: mahendra | Date: 1/22/2008
| Contact mahendra
A copy constructor is called when a new variable is created from an object. The default copy constructor does a shallow copy i.e; the copied object points to same old memory pointed by the parent object. If the object has some dynamic memory or pointers, it is better to create a copy constructor.<br><br>When a new copy constructor is written, assignment operator and destructor also should be written in the class.<br> Source: CoolInterview.com
Answered by: suresh | Date: 2/23/2010
| Contact suresh
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|