-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathperson.cpp
More file actions
40 lines (32 loc) · 741 Bytes
/
Copy pathperson.cpp
File metadata and controls
40 lines (32 loc) · 741 Bytes
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
#include <cstring>
#include <iostream>
using namespace std;
class Person {
public:
typedef enum { BOY = 0, GIRL } SexType;
Person(char *n, int a, SexType s) {
name = new char[strlen(n) + 1];
strcpy(name, n);
age = a;
sex = s;
}
int get_age() const { return this->age; }
Person &add_age(int a) {
age += a;
return *this;
}
~Person() { delete[] name; }
private:
char *name;
int age;
SexType sex;
};
int main() {
Person p((char *)("zhangsan"), 20, Person::BOY);
cout << p.get_age() << endl;
// Person p1("lisi", 1, Person::GIRL);
// Person p2 = p1.add_age(2);
p.add_age(3);
cout << p.get_age() << endl;
return 0;
}