aboutsummaryrefslogtreecommitdiff
path: root/week08/Exercise4.h
blob: 588589eaf0e9ca4b269179619819dd5dfd2398fd (plain) (blame)
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
#include <iostream>

class FloatArray {
	float *numbers;
	int lastUnused;
	int allocated;

	void free();
	void copyFrom(const FloatArray& other);

	void resize();

public:
	FloatArray();
	~FloatArray();
	FloatArray(const FloatArray& other);
	FloatArray& operator=(const FloatArray& other);
	FloatArray(FloatArray&& other);
	FloatArray& operator=(FloatArray&& other);

	void Add(float number);

	// Тези оператори променят аргумента си, затова е по-добре да са член-функции
	FloatArray& operator+=(const FloatArray& other);
	FloatArray& operator+=(float number);
	// По дефиниция не може operator=, operator(), operator[] и operator-> да бъдат имплементирани
	// като приятелски функции
	float& operator[](int index);

	// Тези оператори не променят аргументите си, затова е по-добре да са приятелски
	friend FloatArray operator+(const FloatArray& left, const FloatArray& right);
	friend FloatArray operator+(const FloatArray& left, float right);
	friend bool operator==(const FloatArray& left, const FloatArray& right);
	friend bool operator!=(const FloatArray& left, const FloatArray& right);
	friend std::ostream& operator<<(std::ostream& ostr, const FloatArray& right);
	friend std::istream& operator>>(std::istream& ostr, FloatArray& right);
};