Copy Constructor and Assignment Operator

May 9, 2011 at 6:33am
Question asked in test. Please help.

Last edited on May 10, 2011 at 12:19am
May 9, 2011 at 6:43am
A class needs copy constructor and assignment operators if the class has some pointer objects, in which case the bitwise copy might corrupt your program.
I the class doesn't contain any pointer variable then there is no need for copy cons or assignment op as the compiler shall provide a default optimized one...
May 9, 2011 at 6:45pm
However, there are times when a compiler will refuse to provide a default constructor or assignment operator.

For example when the class contains
1. references
2. constant members.

EDIT:
But I think that it (the compiler) can always magage to produce a default copy constructor *(which may or may not suit your purposes).
Last edited on May 9, 2011 at 6:53pm
Topic archived. No new replies allowed.