SHARE
TWEET

Untitled

a guest Oct 17th, 2019 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top