Copy Constructor
-
Can any one clarify this: What is the advantage of overwriting a copy constructor when C++, by default, providing one. Thanks, Prudhvi.
-
Can any one clarify this: What is the advantage of overwriting a copy constructor when C++, by default, providing one. Thanks, Prudhvi.
Copy Constructor is used to solve the problem of Shallow copy when using dynamic data( as in pointers ). as the default copy constructor does a member wise copy of data members , this operation is undesirable while using pointers as both the pointer members point to the same area in memory . This can have undesired effects . By implementing a copy constructor , one can allocate new memory and make sure that space allocated is different . In the case where memory management isnt required the default COPY cONSTRUCTOR will suffice . Engineering is the effort !
-
Can any one clarify this: What is the advantage of overwriting a copy constructor when C++, by default, providing one. Thanks, Prudhvi.
-
also, remember to always implement a destructor that frees the new memory so that any class that is copied won't cause memory leaks. [insert witty comment here] bdiamond :zzz: