-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSobrecargaDeOperadores2.cpp
More file actions
70 lines (54 loc) · 1.01 KB
/
Copy pathSobrecargaDeOperadores2.cpp
File metadata and controls
70 lines (54 loc) · 1.01 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
#include <iostream>
#include <string>
using namespace std;
class Pessoa
{
private:
string nome;
int id;
public:
void inicializar(string novoNome, int novoId)
{
nome.replace(0, nome.size(), novoNome);
id = novoId;
}
Pessoa(string novoNome, int novoId)
{
//nome.replace(0, nome.size(), novoNome);
//id = novoId;
inicializar(novoNome, novoId);
}
Pessoa(Pessoa& p)
{
inicializar(p.nome, p.id);
}
Pessoa& operator=(Pessoa& p)
{
if(this != &p)
{
inicializar(p.nome, p.id);
}
return *this;
}
string getNome()
{
return nome;
}
int getId()
{
return id;
}
void mudarNome(char c)
{
nome[0] = c;
}
};
int main()
{
Pessoa p1("Felipe", 1), p2("pedro", 2);
p1 = p2;
p1.mudarNome('C');
cout << "Nome: " << p1.getNome() << endl << "ID: " << p1.getId() << endl;
cout << "Nome: " << p2.getNome() << endl << "ID: " << p2.getId() << endl;
return 0;
}