-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshallowcopy.cpp
85 lines (71 loc) · 1.31 KB
/
shallowcopy.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <string.h>
using namespace std;
class Hero
{
private:
int health;
public:
char level;
char *name;
Hero()
{
cout << "Default constructr called " << endl;
name = new char[100];
}
// parametrized constructor called;
Hero(int health)
{
this->health = health;
}
Hero(int health, char level)
{
this->health = health;
this->level = level;
}
void print()
{
cout << endl;
cout << "( "
<< "Health is :- " << this->health << " , ";
cout << "level is :- " << this->level << " , ";
cout << "Name is :- " << this->name << " )";
cout << endl;
}
// another way to get data
int getHealth()
{
return health;
}
char getLevel()
{
return level;
}
void setHealth(int h)
{
this->health = h;
}
void setLevel(char l)
{
this->level = l;
}
void setname(char name[])
{
strcpy(this->name, name);
}
};
int main()
{
Hero h1;
h1.setHealth(100);
h1.setLevel('A');
char name[6] = "rahul";
h1.setname(name);
h1.print();
// using inbuilt default constructor
Hero h2(h1);
h2.print();
h1.name[0] = 'm';
h1.print();
h2.print();
}