#include using namespace std; class Student { private: string* id; //Memory will be allocated dynamically string* name; //Memory will be allocated dynamically double gpa; public: //Default constructor Student():id(new string), name(new string), gpa(0.0) {} //Constructor Student(const string &id, const string &name, double gpa): id(new string(id)), name(new string(name)), gpa(gpa) {} // Copy constructor Student(const Student& other):id(new string(*other.id)), name(new string(*other.name)),gpa(other.gpa) {} //Copy assignment // Student& operator= (const Student& other) { // if(this == &other) { // return *this; // } // delete id; // id = new string(*other.id); // delete name; // name = new string(*other.name); // gpa = other.gpa; // return *this; // } //Copy assignment version 2 Student& operator= (const Student& other) { if( this == &other) { return *this; } //Does not need to do delete and new on *id and *name since they are string objects //string class has copy assignment function defined, copy assignment function takes care of the memory *id = *other.id; *name = *other.name; gpa = other.gpa; return *this; } //Move constructor Student(Student&& temp): id(temp.id), name(temp.name), gpa(temp.gpa) { temp.id = NULL; temp.name = NULL; } //Move assignment //Student& operator= (Student&& temp) { // if( this == &temp) { // return *this; // } // delete id; // id = temp.id; // temp.id = NULL; // delete name; // name = temp.name; // temp.name = NULL; // gpa = temp.gpa; // return *this; //} //Move assignment version 2 Student& operator= (Student&& temp) { if( this == &temp) { return *this; } *id = *temp.id; temp.id = NULL; *name = *temp.name; temp.name = NULL; gpa = temp.gpa; return *this; } //Destructor ~Student(){ cout<<"Student destructor freeing memory (id and name)..."<