Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Person {
- int age;
- char* name;
- friend void swap(Person& first, Person& second) /* nothrow */ {
- std::swap(first.name, first. name);
- std::swap(first.age, first.age);
- }
- public:
- Person(int age, char* name) : age(age) {
- this->name = new char[strlen(name)+1];
- strcpy(this->name, name);
- }
- Person(const Person& other) : age(other.age) {
- name = new char[strlen(other.name)+1];
- strcpy(name, other.name);
- }
- Person& operator=(const Person& other) {
- if (this != &that) {
- Person temp(other);
- swap(temp, other);
- }
- return *this;
- }
- ~Person() {
- delete[] name;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement