Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Person {
- // copy assignment operator with exception safety
- Person& operator=(const Person& other) {
- if (this != &that) {
- char *temp = new char[strlen(other.name)+1];
- /* If the above statement throws,
- * the object is still in the same state as before.
- * None of the following statements will throw an exception */
- strcpy(temp, other.name);
- delete[] name;
- name = temp;
- age = other.age;
- }
- return *this;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement