








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









date::date(char *ip_date){ //Constructor day = 0; month = 0; year = 0; string_date = new char [size]; strcpy(string_date, ip_date); }
//Shallow Copy Constructor date(const date &ip_date) {string_date = ip_date.string_date;}
//Destructor date::~date() {delete[] (string_date);}
date::date(char *ip_date){ //Constructor day = 0; month = 0; year = 0; string_date = new char [size]; strcpy(string_date, ip_date); } //Deep Copy Constructor date(const date &ip_date) { string_date = new char[size]; strcpy(string_date, ip_date.string_date); } //Destructor date::~date() {delete[] (string_date);}
#include “date.h” main() { date today("June 21, 1995"); //Deep copy constructor date extra_day = today; }
data members are also copied. Deep copying may be required whenever you have data members that are pointers.
#include “student.h” /* Member functions of the “Student" class */ Student::Student(char *studentName, char *studentId, char *studentEmail){ name = new char[size]; strcpy(name, studentName); id = new char[size]; strcpy(id, studentId); email = new char[size]; strcpy(email, studentEmail);} Student::~Student(){ delete [] name; delete [] id; delete [] email;} // Deep copy constructor Student::Student(Student &s){ name = new char[size]; strcpy(name, s.name); id = new char[size]; strcpy(id, s.id); email = new char[size]; strcpy(email, s.email);}