-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverloading-classes.cpp
More file actions
73 lines (52 loc) · 1.11 KB
/
Overloading-classes.cpp
File metadata and controls
73 lines (52 loc) · 1.11 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
#include <iostream>
using namespace std;
// Overloading classes
// Link: https://youtu.be/sLQLUed6izY
// Title: Перегрузка конструкторов класса. Что такое перегрузка. Как перегрузить конструктор. Урок#79
// Creator: #SimpleCode
//
class Point
{
public:
Point () // default
{
x = 0;
y = 0;
}
Point (int valueX, int valueY) // questa parte è sempre inculusa nelle classi
// ma di base non fa nulla è vuoto
{ // overloading
x = valueX;
y = valueY;
}
Point (int valueX, bool boolean)
{
x = valueX;
if (boolean)
{
y = 1;
}
else
{
y = - 1;
}
}
void Print ()
{
cout << "X = " << x << "\t Y = " << y << endl << endl;
}
private:
int x;
int y;
};
int main() {
setlocale(LC_ALL, "italian");
Point a;
a.Print();
Point b (18, 40); // non si può fare senza overloading
b.Print();
Point c (10, true); // si possono fare diversi costruttori ma devono avere un senso
// per quella classe li, e non come questo che è inutille
c.Print();
return 0;
}