-
Notifications
You must be signed in to change notification settings - Fork 0
/
tut17.cpp
46 lines (39 loc) · 848 Bytes
/
tut17.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>
using namespace std;
// copy constructor
class Number
{
int a;
public:
Number(void)
{
a = 0;
}
Number(int x)
{
a = x;
}
// when no copy constructor is there, complier supplies it's own copy constructor;
// so even if I remove it , my copy constructor will itself make this
Number(Number &obj1)
{
cout << "Copy constructor called !!" << endl;
a = obj1.a;
}
void show(void)
{
cout << a << endl;
}
};
int main()
{
Number a, b, c(45), z2;
a.show();
b.show();
c.show();
Number x(c); // Copy constructor will invoke
x.show();
z2 = c; // Copy constructor will not invoke as z2 was initialize in line 33;
Number z3 = c; // Copy constructor will invoke as it is initialize here only
return 0;
}