-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2Constructor.cpp
51 lines (39 loc) · 1.22 KB
/
2Constructor.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
// It is a special function always present in class
// Constructor is responsible to create an object
//when we create an object of class, constructor is invoked
//it gets automatically called and only once for a single object
// Employee E1;(in last code) it will make a call to the constructor func present inside the class which is invisible to us.
// Constructor name should be same as of class name
//Constructor should not return anything
#include<bits/stdc++.h>
using namespace std;
//The class is bluprint of object
class Employee{
public:
string Name;
string Company;
int Age;
void Indroduction(){
cout<<"Name:"<<Name<<endl;
cout<<"Company:"<<Company<<endl;
cout<<"Age:"<<Age<<endl;
}
Employee(){ //for E1,E2,E4
cout<<"inside default constructor"<<endl;
}
Employee(string name, string company,int age){ //E3 is using this Constructor
Name=name;
Company=company;
Age=age;
}
};
int main(){
Employee E1,E2,E4; //only these three will go in default constructor
Employee E3("jain","company",20);
E1.Name="riya";
E1.Age=19;
E1.Company="Deshaw";
E1.Indroduction();
E2.Indroduction();
E3.Indroduction();
}