Table of Contents
We've talked a lot about using pointers to share information, but mainly as something that causes problems. We have a pretty good idea of how to handle ourselves when we have pointers among our data members and don't want to share. In that case, we rely on implementing our own deep copying so that every "container" has distinct copies of all of its components.
For some data structures, this is OK. If we are using a pointer mainly to give us access to a dynamically allocated array, we can copy the entire array as necessary. In the example shown here, we would want each catalog to get its own distinct array of books. So we would implement a deep copy for the assignment operator and copy constructor, and delete the allBooks pointer in the destructor.
But not every data structure can be treated this way. Sometimes, sharing is essential to the behavior of the data structure that we want to implement. (If nothing else, Our study ofhas highlighted the fact that many data structures are inherently "sharing".)