CS212: Object Oriented Analysis and Design Lecture 10: Copy constructor-II
Copy copy: revisited Main Constructor Copy Constructorh f(): global functionx=h
What happens if we don’t use it? Compiler creates one for you in the case of simple structures The default primitive behaviour: a bit-copy. C++ compiler will still automatically create a copy-constructor if you don’t make one The process the compiler goes through to synthesize a copy- constructor is called member-wise initialization.
Issues with pointers 50x A B {B=A;} Initial object Duplicate object
Deep vs Shallow copy Copy constructor is called only for initializations For assignment ? Operator overload ??