-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinheritCopyConstructor.cpp
69 lines (61 loc) · 1.02 KB
/
inheritCopyConstructor.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
using namespace std;
class First
{
private:
int num1, num2;
public:
First(int n1=0, int n2=0) : num1(n1), num2(n2)
{ }
void ShowData() { cout<<num1<<", "<<num2<<endl; }
First(const First &ref)
{
num1 = ref.num1;
num2 = ref.num2;
}
First& operator=(const First&ref)
{
cout<<"First& operator=()"<<endl;
num1=ref.num1;
num2=ref.num2;
return *this;
}
};
class Second : public First
{
private:
int num3, num4;
public:
Second(int n1, int n2, int n3, int n4)
: First(n1, n2), num3(n3), num4(n4)
{ }
void ShowData()
{
First::ShowData();
cout<<num3<<", "<<num4<<endl;
}
Second(const Second & ref): First(ref)
{
num3 = ref.num3;
num4 = ref.num4;
}
/*
Second& operator=(const Second &ref)
{
cout<<"Second& operator=()"<<endl;
// First::operator=(ref);
num3=ref.num3;
num4=ref.num4;
return *this;
}
*/
};
int main(void)
{
Second ssrc(111, 222, 333, 444);
Second scpy(ssrc);
//Second scpy(0, 0, 0, 0);
//scpy=ssrc;
scpy.ShowData();
return 0;
}