-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05_inline_constructor.cpp
More file actions
42 lines (36 loc) · 975 Bytes
/
Copy path05_inline_constructor.cpp
File metadata and controls
42 lines (36 loc) · 975 Bytes
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
#include <iostream>
using namespace std;
class Customer
{
string name;
int account_number;
int balance;
public:
// default constructor
Customer()
{
name = "sakshi";
account_number = 5;
balance = 100;
}
inline Customer(string a, int b, int c) : name(a),account_number(b),balance(c){
}
void display()
{
cout << name << " " << account_number << " " << balance << endl;
}
};
int main()
{
Customer A1;
Customer A2("swapnil", 10, 4000);
A1.display();
A2.display();
}
/*
one more use case of constructor is that it stops the execution of code when there is an error
for example if we are opening a file, but that file doesnt exist then
the exexution stops and gives error instead running the entire code and giving an error
which wastes resources
another example- we need memory of var= new int[100]-- if we dont get array of 100 allocated in heap then exe stops --error
*/