-
Notifications
You must be signed in to change notification settings - Fork 0
/
operator overloading.cpp
64 lines (50 loc) · 1020 Bytes
/
operator overloading.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
// Last sanity check: 2020-05-18
//
// main.cpp
// Cpp
//
// Created by Alex Seceleanu on 4/9/18.
// Copyright © 2018 Alex Seceleanu. All rights reserved.
//
#include <stdio.h>
#include <iostream>
using namespace std;
class Test{
int id;
string name;
public:
Test(): id(0), name("name") {}
Test(int id, string name):
id(id), name(name) {}
void print() const
{
cout<<id << " | " << name<< endl;
}
const Test &operator=(const Test &eg)
{
cout << "Egal customizat"<<endl;
id = eg.id;
name = eg.name;
return *this;
}
Test(const Test ©)
{
cout<< "Copy constructor"<<endl;
//id = copy.id;
//name = copy.name;
*this = copy;
}
};
int main()
{
Test t1 = Test(1, "Alex");
t1.print();
Test t2 = Test(2, "Lori");
t2.print();
t2 = t1;
t1.print();
t2.print();
Test t3 = t2;
t3.print();
return 0;
}