I have a class called Directory with certain members followed by a copy constructor.
class Directory{ private: char * Name; int Telephone_Number; char * Address; public: Directory (Directory & b) { Name = new char [10]; //Just assume that the name will not be greater than //10 characters Address = new char [30]; //Same here strcpy (Name, b.Name); Telephone_Number = b.Telephone_Number; strcpy (Address, b.Address); } }; I wanted to know if my copy constructor would perform deep copy or shallow copy. I understand that it is deep copying Address and Name because new memory is being allocated for them, but what about Telephone_Number?
Is my code doing shallow copying or deep copying? Could anyone explain copy constructors in general to me?
deletetheNameandAddressbefore allocatingnewmemory.char*tostd::stringand remove thatnewoperator!