-
Notifications
You must be signed in to change notification settings - Fork 0
/
constructor.cpp
46 lines (45 loc) · 1.09 KB
/
constructor.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
#include <iostream>
#include<string>
using namespace std;
class Teacher{
private:
double salary;
public:
//non-parametrized constructor
// Teacher(){
// dept = "IT";
// }
//properties /attributes
string name;
string dept;
string subject;
//parametrized constructor
Teacher(string name,string dept,string subject,double salary){
this->name = name;
this->dept = dept;
this->subject = subject;
this->salary = salary;
}
//custom copy constructor
Teacher(Teacher &orgObj){
cout<<"i am custom copy constructor"<<endl;
this->name=orgObj.name;
this->dept=orgObj.dept;
this->subject=orgObj.subject;
this->salary=orgObj.salary;
}
void getInfo(){
cout<<"name: "<<name<<endl;
cout<<"subject: "<<subject<<endl;
}
};
int main(){
//constructor call
Teacher t1("vikash","IT","C++",25000);
// t1.getInfo();
// cout<<t1.dept<<endl;
// Teacher t2(t1); //default copy constructor
Teacher t2(t1); //custom copy constructor
t2.getInfo();
return 0;
}