-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtut49.cpp
More file actions
44 lines (39 loc) · 861 Bytes
/
tut49.cpp
File metadata and controls
44 lines (39 loc) · 861 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
43
44
#include <iostream>
using namespace std;
/*
Syntax for initialization list in constructor:
constructor (argument-list) : initilization-section
{
assignment + other code;
}
class Test{
int a;
int b;
public:
Test(int i, int j) : a(i), b(j){constructor-body}
};
*/
class Test
{
int a;
int b;
public:
// Test(int i, int j) : a(i), b(j)
// Test(int i, int j) : a(i), b(i+j)
// Test(int i, int j) : a(i), b(2 * j)
// Test(int i, int j) : a(i), b(a + j)
// Test(int i, int j) : b(j), a(i+b) -->RED Flag this will create problems because a will be initialized first
Test(int i, int j)
{
a = i;
b = j;
cout << "Constructor executed"<<endl;
cout << "Value of a is "<<a<<endl;
cout << "Value of b is "<<b<<endl;
}
};
int main()
{
Test t(4, 6);
return 0;
}