-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverload_constructor.cpp
More file actions
53 lines (42 loc) · 877 Bytes
/
Copy pathoverload_constructor.cpp
File metadata and controls
53 lines (42 loc) · 877 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
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <string>
using namespace std;
class Human{
private:
int age;
string name;
public:
Human(){
cout << "default constructor"<<endl;
age = 0;
name = "noname";
}
Human(string iname){
cout << "constructor with name as the parameter"<<endl;
age = 0;
name = iname;
}
Human(int iage){
cout << "constructor with age as the parameter"<<endl;
age = iage;
name = "noname";
}
Human(string iname,int iage){
cout << "constructor with age and name as the parameter"<<endl;
age = iage;
name = iname;
}
void display(){
cout <<name <<endl<<age<<endl;
}
};
int main()
{
Human anil;
anil.display();
Human andy("andy");
andy.display();
Human alex("alex",25);
alex.display();
return 0;
}