-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDistuttore.cpp
More file actions
56 lines (38 loc) · 1.22 KB
/
Distuttore.cpp
File metadata and controls
56 lines (38 loc) · 1.22 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
#include <iostream>
using namespace std;
// Distruttore
// Link: https://youtu.be/kXng09pmfwM
// Title: Деструктор что это. Зачем нужен деструктор класса в ООП. Деструктор с параметрами. Перегрузка. #80
// Creator: #SimpleCode
//
class MyClass
{
int data; // privato di default
public:
MyClass (int value)
{
data = value;
cout << "Costruttore " << data << endl;
}
~ MyClass () // soltanto uno per classe, non si può overloadare come i costruttori
{ // non ha parametri, non li può avere
cout << "Distruttore " << data << endl;
} // si attivà solo quando si esce dalla main (non si vede più)
// si distugono in modo inverso dall'ultimo all'primo
// nelle classi semplici come questa non ha senso, ma quando
// si lavora con i vettori con la memoria dinamica bisogna
// pensare alla liberazione delle risorse impiegato per essp
};
void Foo ()
{
cout << "Foo inizio" << endl;
MyClass a (10);
cout << "Foo fine" << endl;
} // si distuggerà qui, dopo esequzione della procedura foo
int main() {
setlocale(LC_ALL, "italian");
// MyClass a (10);
// MyClass b (20);
Foo();
return 0;
}