forked from Light-City/CPlusPlusThings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperson.cpp
More file actions
41 lines (35 loc) · 623 Bytes
/
Copy pathperson.cpp
File metadata and controls
41 lines (35 loc) · 623 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
41
#include<iostream>
#include<cstring>
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("zhangsan",20,Person::BOY);
cout<<p.get_age()<<endl;
return 0;
}