-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c++
88 lines (76 loc) · 1.76 KB
/
main.c++
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
#include "Vector.c++"
class Vector3
{
public:
float x = 0.0f, y = 0.0f, z = 0.0f;
int *memory_block;
Vector3() { memory_block = new int[5]; }
Vector3(float scala) : x(scala), y(scala), z(scala)
{
memory_block = new int[5];
}
Vector3(float x, float y, float z) : x(x), y(y), z(z)
{
memory_block = new int[5];
}
Vector3(const Vector3 &other) : x(other.x), y(other.y), z(other.z)
{
memory_block = new int[5];
}
Vector3(Vector3 &&other) : x(other.x), y(other.y), z(other.z)
{
memory_block = other.memory_block;
other.memory_block = nullptr;
}
~Vector3()
{
delete[] memory_block;
}
Vector3 &operator=(const Vector3 &other) = delete;
Vector3 &operator=(const Vector3 &&other)
{
x = other.x;
y = other.y;
z = other.z;
return *this;
}
};
template <typename T>
void print(const Vector<T> &vector)
{
for (size_t i = 0; i < vector.Size(); i++)
{
std::cout << vector[i] << std::endl;
}
}
void print(const Vector<Vector3> &vector)
{
for (size_t i = 0; i < vector.Size(); i++)
{
std::cout << vector[i].x << " " << vector[i].y << " " << vector[i].z << std::endl;
}
}
int main(int argc, char const *argv[])
{
Vector<Vector3> vector;
vector.EmplaceBack(1.0f);
vector.EmplaceBack(1.0, 2.0, 3.0);
vector.EmplaceBack(2.0f);
print(vector);
vector.PopBack();
vector.PopBack();
vector.Clear();
Vector<int> v;
v.Pushback(1);
v.Pushback(2);
v.Pushback(3);
v.Pushback(4);
for (Vector<int>::Iterator it = v.begin();
it != v.end(); it++)
{
std::cout << *it << std::endl;
}
print(v);
return 0;
}