-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray.cpp
61 lines (50 loc) · 974 Bytes
/
array.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
#include <iostream>
using namespace std;
template <class T>
class Array
{
T** data;
unsigned int size_var;
public:
Array(unsigned int s, const T& d): size_var(s)
{
data = new T* [size_var];
for (unsigned int i = 0 ; i < size_var ; i++)
data[i] = new T(d);
}
Array(const Array& a): size_var(a.size_var)
{
data = new T* [size_var];
for (unsigned int i = 0 ; i < size_var ; i++)
data[i] = new T(*(a.data[i]));
}
~Array(void)
{
for (unsigned int i = 0 ; i < size_var ; i++)
delete data[i];
delete[] data;
}
unsigned int size(void) const
{
return size_var;
}
T& operator [] (unsigned int p)
{
return *(data[p]);
}
const T& operator [] (unsigned int p) const
{
return *(data[p]);
}
};
int main(void)
{
Array <unsigned int> a(10, 0);
for (unsigned int i = 0 ; i < a.size() ; i++)
a[i] = i;
Array <unsigned int> b(a);
for (unsigned int i = 0 ; i < b.size() ; i++)
cout << b[i] << ' ';
cout << endl;
return 0;
}