-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerson.cpp
More file actions
53 lines (44 loc) · 1.24 KB
/
Person.cpp
File metadata and controls
53 lines (44 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "Person.h"
#include <cstring>
Person::Person(const char* name, const Address &address) : address(address) {
this->name = new char[strlen(name) + 1];
strcpy(this->name, name);
}
Person::~Person() {
delete [] this->name;
}
Person::Person(const Person &p) : address(p.address){
this->name = new char[strlen(p.name) + 1];
strcpy(this->name, p.name);
}
void Person::setName(const char* name){
delete [] this->name;
this->name = new char[strlen(name) + 1];
strcpy(this->name, name);
}
void Person::setAddress(const Address &a){
this->address = a;
}
const char* Person::getName() const{
return this->name;
}
Address Person::getAddress() const{
return this->address;
}
void Person::show() const {
std::cout << "Person { \n name: " << this->name << "\n ";
this->address.show();
std::cout << "\n}";
}
Person& Person::operator=(const Person& that){
if(this == &that) return *this;
delete [] this->name;
this->name = new char[strlen(name) + 1];
strcpy(this->name, name);
this->address = that.address;
return *this;
}
std::ostream& operator<<(std::ostream& os, const Person& that){
os << "Person { \n name: " << that.name << "\n " << that.address << "\n}";
return os;
}