-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew22ConstructorPractice.cpp
More file actions
49 lines (43 loc) · 1.03 KB
/
Copy pathnew22ConstructorPractice.cpp
File metadata and controls
49 lines (43 loc) · 1.03 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
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
class Player
{
private:
std::string name;
int level;
int exp;
public:
Player(std::string name="None",int level=0,int exp=0);
std::string get_name(){return name;}
int get_exp(){return exp;}
int get_level(){return level;}
//Copy constructor
Player(const Player &source);
~Player(){cout<<"Destructor called for:"<<name<<endl;}
};
Player::Player(const Player &source)
:Player(source.name,source.level,source.exp)
{
cout<<"Copy constructor -made copy: "<<source.name<<endl;
}
Player::Player(std::string name_val,int level_val,int exp_val)
:name{name_val},level{level_val},exp{exp_val}
{
}
//Player::std::string name get_name(){return name}
//Player::int get_level(){return level}
//Player::int get_exp(){return exp}
void display_player(Player p)
{
cout<<p.get_name()<<endl;
cout<<p.get_level()<<endl;
cout<<p.get_exp()<<endl;
}
int main()
{
Player aary{"Aary Kinge",1,2};
display_player(aary);
return 0;
}