-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path16constructor.cpp
49 lines (45 loc) · 926 Bytes
/
16constructor.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
// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;
class student{
string name;
public:
int age;
bool gender;
void setName(string s){
name=s;
}
void getName(){
cout<<name<<endl;
}
student(){
cout<<"Default Constructor"<<endl;
}
student(string s,int a,bool k){
cout<<"Parameterised Constructor"<<endl;
name=s;
age=a;
gender=k;
}
student(student &s){
cout<<"Copy Constructor"<<endl;
name=s.name;
age=s.age;
gender=s.gender;
}
void printInfo(){
cout<<"Name=";
cout<<name<<endl;
cout<<"Age=";
cout<<age<<endl;
cout<<"Gender=";
cout<<gender<<endl;
}
};
int main() {
student a("Tim",18,1);
student b;
//or student c(a);
student c=a;//by default shallow copy else here deep copy as copy constructor present
return 0;
}