Hi guys,
I know what a copy constructor and an assignment operator is.
I have read that in a copy constructor, deep copy () happens and in assignment operator shallow copy happens. My question is how?
NOTE:
deep copy-->implies duplicating an object
shallow copy--> is a reference copy, i.e. just a pointer to a shared data block
Can someone please make me understand how actually the copying happens in both copy constructor and an assignment operator
Thanks
I know what a copy constructor and an assignment operator is.
I have read that in a copy constructor, deep copy () happens and in assignment operator shallow copy happens. My question is how?
NOTE:
deep copy-->implies duplicating an object
shallow copy--> is a reference copy, i.e. just a pointer to a shared data block
Code:
class MyObject
{
public:
MyObject(); // Default constructor
MyObject(MyObject const & a); // Copy constructor ( copying happens by deep copy)
MyObject & operator = (MyObject const & a) // Assignment operator (copying happens by shallow copy)
}
Thanks
Comment