I wanted to know Why compiler provides default copy constructor..Whats the strategy behind that idea.
Thanks in Advance.
I'm not sure what the "official line is" (don't have Strastroup's book near me) and I'm sure someone will dig it up.
However, in most cases shallow copies and default initialization is "good enough", so it's better for the compiler to provide them than to have the developerexplicitly write them.
If the developer wrote this trivial copy constructors and the fields later change, it is up to that user to make the changes and there could be serious errors if he forgets (e.g., what are these fields constructed as?).
By only having users write copy constructors when there really is a need to do something fancy (like deep copying), you reduce the frequency of these errors.