|
||||||||
Question: Passing1. What will happen when we pass by value a Class that contains dynamic memory. For example, consider our stack class implemented with a linked list: Answer: It will only make a shallow copy.....the actually pointer in the class will point to the real list.
2) What is the potential problem with the issue in number 1? Answer: The shallow copy only the class data members, and does not copy any pointed-to data, like the linked list of data nodes. Hence, ashallow copy shares the pointed to data with the original class object. You must be aware that changes you make to the shared data in the function recieving a shallow copy of the Struct class instance will be changes made in the original object.
|
||||||||
© Lynne Grewe |