I've run across this code and have seen similar code before, but I'm not sure what it means
Why is there a & after Person? What is it saying to the compiler?Code://--- file Person.h . . . class Person { private: char* _name; int _id; public: Person& Person::operator=(const Person& p); . . . } //--- file Person.cpp . . . //=================================================== operator= Person& Person::operator=(const Person& p) { if (this != &p) { // make sure not same object delete [] _name; // Delete old name's memory. _name = new char[strlen(p._name)+1]; // Get new space strcpy(_name, p._name); // Copy new name _id = p._id; // Copy id } return *this; // Return ref for multiple assignment }//end operator=




Reply With Quote