Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement