-
Notifications
You must be signed in to change notification settings - Fork 548
/
Copy pathmain.cpp
52 lines (41 loc) · 988 Bytes
/
main.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
#include <cstdlib>
#include <iostream>
#include <cstring>
struct Vector {
size_t m_size;
int *m_data;
Vector(size_t n) {
m_size = n;
m_data = (int *)malloc(n * sizeof(int));
}
~Vector() {
free(m_data);
}
Vector(Vector const &other) {
m_size = other.m_size;
m_data = (int *)malloc(m_size * sizeof(int));
memcpy(m_data, other.m_data, m_size * sizeof(int));
}
Vector &operator=(Vector const &other) {
m_size = other.m_size;
m_data = (int *)realloc(m_data, m_size * sizeof(int));
memcpy(m_data, other.m_data, m_size * sizeof(int));
return *this;
}
size_t size() {
return m_size;
}
void resize(size_t size) {
m_size = size;
m_data = (int *)realloc(m_data, m_size);
}
int &operator[](size_t index) {
return m_data[index];
}
};
int main() {
Vector v1(32);
Vector v2(64);
v2 = v1;
return 0;
}