-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray2D.cpp
More file actions
53 lines (46 loc) · 1.23 KB
/
Copy pathArray2D.cpp
File metadata and controls
53 lines (46 loc) · 1.23 KB
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
#include "Array2D.h"
#include "WordsearchExceptions.h"
template <typename T>
Array2D<T>::Array2D(unsigned width, unsigned height) : width_(width),
height_(height),
data_(new T[width * height])
{
}
template <typename T>
Array2D<T>::Array2D(Array2D<T> const& copy) : width_(copy.width_),
height_(copy.height_)
{
delete[] data_;
data_(new T[width_ * height_]);
if (copy.data)
{
for (unsigned i=0; i < width_ * height_; ++i)
data_[i] = copy.data_[i];
}
}
template <typename T>
Array2D<T>::~Array2D()
{
delete[] data_;
}
template <typename T>
T& Array2D<T>::operator() (unsigned x, unsigned y)
{
if (inRange(x, y))
return data_[x + y * width_];
else
throw OutOfRange();
}
template <typename T>
T const& Array2D<T>::operator() (unsigned x, unsigned y) const
{
if (inRange(x, y))
return data_[x + y * width_];
else
throw OutOfRange();
}
template <typename T>
bool Array2D<T>::inRange(unsigned x, unsigned y) const
{
return (x < width_ && y < height_);
}