Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. class Person {
  2.  
  3. // copy assignment operator with exception safety
  4. Person& operator=(const Person& other) {
  5. if (this != &that) {
  6. char *temp = new char[strlen(other.name)+1];
  7. /* If the above statement throws,
  8. * the object is still in the same state as before.
  9. * None of the following statements will throw an exception */
  10. strcpy(temp, other.name);
  11. delete[] name;
  12. name = temp;
  13. age = other.age;
  14. }
  15. return *this;
  16. }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement