SHARE
TWEET

Untitled

a guest Oct 17th, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Person {
  2.     int age;
  3.     char* name;
  4.  
  5.     friend void swap(Person& first, Person& second) /* nothrow */ {
  6.         std::swap(first.name, first. name);
  7.         std::swap(first.age, first.age);
  8.     }
  9. public:
  10.     Person(int age, char* name) : age(age) {
  11.         this->name = new char[strlen(name)+1];
  12.         strcpy(this->name, name);
  13.     }
  14.  
  15.     Person(const Person& other) : age(other.age) {
  16.         name = new char[strlen(other.name)+1];
  17.         strcpy(name, other.name);
  18.     }
  19.  
  20.     Person& operator=(const Person& other) {
  21.         if (this != &that) {
  22.             Person temp(other);
  23.             swap(temp, other);
  24.         }
  25.         return *this;
  26.     }
  27.  
  28.     ~Person() {
  29.         delete[] name;
  30.     }
  31. }
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