-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathzad7.cpp
More file actions
129 lines (93 loc) · 2.26 KB
/
Copy pathzad7.cpp
File metadata and controls
129 lines (93 loc) · 2.26 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <iostream>
#include <cstring>
#include <cstdlib> //free && mallock w cstdlib
//las
using namespace std;
class Person {
char* name; //private
public:
friend class Couple;
friend ostream& operator<<(ostream& str, const Person& os)
{
str<<os.name;
};
Person(const char* n)
{
name = (char*)n;
cout<<"konstr1 "<<name<<endl;
};
Person(const Person& os)
{
name = os.name;
cout<<"konstr 2 "<<name<<endl;
};
Person& operator=(const Person& os)
{
this->name = os.name;
return *this; //this to wskaznik na aktualny obiekt
};
~Person()
{
free(name); //funkcja zwalniajaca pamiec
cout<<"destr"<<endl;
};
char* getName(){
return name;
};
};
class Couple {
Person *husb, *wife;
public:
friend ostream& operator<<(ostream& str, const Couple& p)
{
str<<"He: "<<*p.husb<<", She: "<<*p.wife;
};
Couple(const char* m, const char* z)
{
husb = new Person(m);
wife = new Person(z);
cout<<"coup1"<<endl;
};
Couple(const Couple& p)
{
husb = new Person(*p.husb);
wife = new Person(*p.wife);
cout<<"coup2"<<endl;
};
Couple& operator=(const Couple& p)
{
this->husb = new Person(*p.husb);
this->wife = new Person(*p.wife);
return *this;
};
~Couple()
{
free(husb->name);
free(wife->name);
free(husb);
free(wife);
};
};
int main(void) {
Couple *c1 = new Couple("John","Sue");
Couple c2("Bert","Elsa");
*c1 = c2;
Couple c3(*c1);
delete c1;
cout << c3 << endl;
/*
Person person1("naaapis");
Person person2(person1);
Person person3("Waldek");
cout<<person1<<" "<<person2<<endl;
person1 = person3;
cout<<person1<<endl;
Couple c2("Bert","Elsa");
Couple c3(c2);
Couple c4("Benny","Ann");
c3 = c4;
cout<<c3<<endl;
*/
//system("PAUSE");
return 0;
}